// author: xay5421
// created: Wed Jul  7 22:49:26 2021
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
template<typename T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<typename T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
int T,n,num[(1<<16)+5],dep[(1<<16)+5],ans[(1<<16)+5];
vector<int>e[(1<<16)+5];
int a[(1<<16)+5];
bool vis[(1<<16)+5][20];
void dfs(int k1){
	if(k1>=(1<<n)){
		throw 1;
	}
	rep(i,0,n-1){
		bool err=0;
		rep(j,0,n-1)if(vis[k1^(1<<j)][i])err=1;
		if(err)continue;
		rep(j,0,n-1)vis[k1^(1<<j)][i]=1;
		a[k1]=i;
		dfs(k1+1);
		rep(j,0,n-1)vis[k1^(1<<j)][i]=0;
	}
}
int main(){
	rd(T);
	while(T--){
		rd(n);
		rep(i,0,(1<<n)-1)e[i].clear(),num[i]=0,dep[i]=-1;
		rep(i,1,n<<(n-1)){
			int u,v;
			rd(u),rd(v);
			e[u].push_back(v);
			e[v].push_back(u);
		}
		dep[0]=0;
		queue<int>q;
		q.push(0);
		while(!q.empty()){
			int k1=q.front();
			q.pop();
			if(num[k1]==0){
				rep(i,0,n-1)dep[e[k1][i]]=dep[k1]+1,num[e[k1][i]]|=1<<i,q.push(e[k1][i]);
			}else{
				rep(i,0,n-1){
					if(dep[e[k1][i]]==-1){
						dep[e[k1][i]]=dep[k1]+1;
						q.push(e[k1][i]);
					}
					if(dep[e[k1][i]]==dep[k1]+1)num[e[k1][i]]|=num[k1];
				}
			}
		}
		rep(i,0,(1<<n)-1)ans[num[i]]=i;
		rep(i,0,(1<<n)-1)printf("%d ",ans[i]);
		puts("");
		if((n&(n-1))==0){
			rep(i,0,(1<<n)-1)memset(vis[i],0,sizeof(vis[i])),a[i]=0;
			try{
				dfs(0);
			}catch(const int&x){
				rep(i,0,(1<<n)-1)printf("%d ",a[num[i]]);
				puts("");
			}
		}else puts("-1");
	}
	return 0;
}
