#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N=16;
int t,n;
int f[1<<N],c[1<<N],pos[1<<N];
vector<int> v[1<<N];
void prepare(){
    int sl=0;
    for(auto i:v[0])
        f[1<<sl]=i, pos[i]=1<<(sl++);
}
int main(){
    for(int i=0;i<1<<N;i++)
        for(int j=0;j<N;j++){
            if(i&(1<<j)) continue;
            c[i|1<<j]=c[i]^j;
        }
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1,a,b;i<=n*(1<<(n-1));i++){
            cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
        }
        for(int i=1;i<1<<n;i++) pos[i]=f[i]=-1, sort(begin(v[i]),end(v[i]));
        prepare();
        for(int i=1;i<1<<n;i++){
            if(f[i]!=-1) continue;
            int v1=0,v2=0;
            for(int j=0;j<n;j++)
                if(i&(1<<j)){
                    if(v1){v2=f[i^(1<<j)]; break;}
                    v1=f[i^(1<<j)];
                }
            for(auto j:v[v1]){
                int x=lower_bound(begin(v[v2]),end(v[v2]),j)-begin(v[v2]);
                if(v[v2][x]==j&&pos[j]==-1){
                    pos[j]=i, f[i]=j;
                    break;
                }
            }
        }
        for(int i=0;i<1<<n;i++) cout<<f[i]<<' ', v[i].clear();
        cout<<'\n';
        if((1<<n)%n){cout<<"-1\n"; continue;}
        for(int i=0;i<1<<n;i++) cout<<c[pos[i]]<<' ';
        cout<<'\n';
    }
    return 0;
}
