#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define ld long double
#define pii pair<int,int>
#define pdd pair<db,db>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};
const double eps=1e-6;
const int inf=1e9+7;
const int mod=998244353;
const int N=2e5+10,M=N<<1;
struct edge{
int v,ne;
}e[M];
int h[N],idx;
void add(int a,int b){
e[idx]={b,h[a]};
h[a]=idx++;
}
int a[N],w[N];
int n,m;
void dfs(int u,int fa,int f){
for(int i=h[u];~i;i=e[i].ne){
int v=e[i].v;
if(v==fa) continue;
dfs(v,u,1-f);
if(f==0) a[v]=m,w[i/2]=m+n;
else a[v]=m+n,w[i/2]=m;
m++;
}
}
void solve(){
cin>>n;
int x,y;
n=pow(2,n);
m=1;idx=0;
for(int i=1;i<=n;i++) h[i]=-1;
for(int i=1;i<n;i++){
cin>>x>>y;
add(x,y),add(y,x);
}
a[1]=n;
dfs(1,-1,0);
cout<<1<<'\n';
for(int i=1;i<=n;i++) cout<<a[i]<<' ';
cout<<'\n';
for(int i=0;i<n-1;i++) cout<<w[i]<<' ';
cout<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie();cout.tie();
int T=1;
cin>>T;
while(T--){
solve();
}
return 0;
}
74. Search a 2D Matrix | 71. Simplify Path |
62. Unique Paths | 50. Pow(x, n) |
43. Multiply Strings | 34. Find First and Last Position of Element in Sorted Array |
33. Search in Rotated Sorted Array | 17. Letter Combinations of a Phone Number |
5. Longest Palindromic Substring | 3. Longest Substring Without Repeating Characters |
1312. Minimum Insertion Steps to Make a String Palindrome | 1092. Shortest Common Supersequence |
1044. Longest Duplicate Substring | 1032. Stream of Characters |
987. Vertical Order Traversal of a Binary Tree | 952. Largest Component Size by Common Factor |
212. Word Search II | 174. Dungeon Game |
127. Word Ladder | 123. Best Time to Buy and Sell Stock III |
85. Maximal Rectangle | 84. Largest Rectangle in Histogram |
60. Permutation Sequence | 42. Trapping Rain Water |
32. Longest Valid Parentheses | Cutting a material |
Bubble Sort | Number of triangles |
AND path in a binary tree | Factorial equations |