#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
int t,n,a[100011],q[100011],popcnt[100011],lg[100011],cur[100011],nxt[100011],ans[100011],id[100011];bool in[100011],out[100011];
struct edge{int v,next;edge(){}edge(int _v,int _next){v=_v;next=_next;}}e[2000011];int head[100011],sz;
void init(){memset(head,-1,sizeof(head));sz=0;}void insert(int u,int v){e[++sz]=edge(v,head[u]);head[u]=sz;}
void bfs()
{
	queue<int> q;q.push(0);id[0]=0;in[0]=out[0]=1;int cnt=0;for(int i=head[0];~i;i=e[i].next)id[e[i].v]=1<<cnt,++cnt,q.push(e[i].v),in[e[i].v]=1;
	while(!q.empty())
	{
		int p=q.front();q.pop();out[p]=1;
		for(int i=head[p];~i;i=e[i].next)
		{
			if(!out[e[i].v])id[e[i].v]|=id[p];
			if(!in[e[i].v])q.push(e[i].v),in[e[i].v]=1,out[e[i].v]=0;
		}
	}
}
int main()
{
	lg[0]=-1;for(int i=1;i<65536;++i)popcnt[i]=popcnt[i>>1]+(i&1),lg[i]=lg[i>>1]+1;
	scanf("%d",&t);while(t--)
	{
		scanf("%d",&n);for(int i=0;i<1<<n;++i)head[i]=-1,in[i]=0,id[i]=0,out[i]=0;sz=0;
		for(int i=1;i<=n*(1<<n-1);++i){int u,v;scanf("%d%d",&u,&v);insert(u,v);insert(v,u);}
		bfs();for(int i=0;i<1<<n;++i)a[id[i]]=i;for(int i=0;i<1<<n;++i)printf("%d ",a[i]);putchar(10);
		if(popcnt[n]!=1){printf("-1\n");continue;}
		cur[0]=cur[1]=0;
		for(int m=2;m<=n;m<<=1)
		{
			for(int j=0;j<1<<(m>>1);++j)nxt[j]=cur[j];
			for(int j=0;j<1<<(m>>1);++j)
			{
				int res=0;
				for(int k=0;k<(m>>1);++k)if(j>>k&1)res^=k;
				if(popcnt[j]&1)res|=1<<lg[m>>1];
				for(int k=0;k<1<<(m>>1);++k)nxt[j<<(m>>1)|k]=cur[k]^res;
			}
			for(int j=0;j<1<<m;++j)cur[j]=nxt[j];
		}
		for(int i=0;i<1<<n;++i)ans[a[i]]=cur[i];
		for(int i=0;i<1<<n;++i)printf("%d ",ans[i]);putchar(10);
	}return 0;
}