#include<bits/stdc++.h>
using namespace std;
#define py cout<<"Yes\n"
#define pn cout<<"No\n"
#define pb push_back
#define ll long long
#define mod 998244353
#define N 1000005
#define eps 1e-8
#define db double
int T;vector<int>son[N];int n,i,x,j,y,to[N],rev[N],vst[N];queue<int>q;
int main(){cin>>T;while(T--){cin>>n;for(i=0;i<(1<<n);++i)vst[i]=rev[i]=0,son[i].clear();for(i=1;i<=(n<<n-1);++i){cin>>x>>y,son[x].push_back(y),son[y].push_back(x);}
		vst[0]=1;for(i=0;i<son[0].size();++i){vst[son[0][i]]=1;q.push(son[0][i]);rev[son[0][i]]=1<<i;}while(q.size()){x=q.front();q.pop();
			for(i=0;i<son[x].size();++i){if(!vst[son[x][i]]){rev[son[x][i]]|=rev[x];if(rev[son[x][i]]!=rev[x])q.push(son[x][i]),vst[son[x][i]]=1;}}}
		for(i=0;i<(1<<n);++i)to[rev[i]]=i;for(i=0;i<(1<<n);++i)cout<<to[i]<<" ";cout<<"\n";if((n&-n)==n){for(i=0;i<(1<<n);++i){
					for(j=x=0;j<n;++j)if((i>>j)&1)x^=j;vst[to[i]]=x;}for(i=0;i<(1<<n);++i)cout<<vst[i]<<" ";cout<<"\n";}else cout<<"-1\n";}}