#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <map>
#include "stdio.h"
using namespace std;

int t;
int n;
vector<int> e[66000];
int a[66000];
int c[66000];
int ans[66000];

int main() {
    ios_base::sync_with_stdio(false);

    cin>>t;
    for (int it=0; it<t; it++) {
        cin>>n;

        for (int i=0; i<(1<<n); i++) {
            e[i].clear();
            a[i] = -1;
            c[i] = -1;
        }

        for (int i=0; i<n*(1<<(n-1)); i++) {
            int a, b;
            cin>>a>>b;

            e[a].push_back(b);
            e[b].push_back(a);
        }

        map<int,int> all;
        for (int i=0; i<(1<<n); i++) {
            //cout<<i<<" "<<a[i]<<endl;
            if (i == 0) {
                a[0] = 0;
                all[0] = 0;
                for (int j=0; j<n; j++) {
                    a[(1<<j)] = e[0][j];
                    all[e[0][j]] = (1<<j);
                }
                continue;
            }
            if (a[i] == -1) {
                set<int> possible;
                bool init = false;
                for (int j = 0; j<n; j++) {
                    int other = (1<<j)^i;
                    //cout<<other<<" "<<a[other]<<endl;
                    if (a[other] != -1) {
                        set<int> tmp;
                        for (int k=0; k<n; k++) if (all.find(e[a[other]][k]) == all.end()) {
                            tmp.insert(e[a[other]][k]);
                        }
                        if (init) {
                            set<int> intersect;
                            set_intersection(possible.begin(), possible.end(),
                                             tmp.begin(), tmp.end(),
                            std::inserter(intersect, intersect.begin()));
                            possible = intersect;
                        } else {
                            init = true;
                            possible = tmp;
                        }
                    }
                }
                if (possible.size() == 0) {
                    cout<<"ERROR"<<endl;
                    return 0;
                }
                a[i] = *possible.begin();
            }
        }

        for (int i=0; i<(1<<n); i++) cout<<a[i]<<" "; cout<<endl;

        if ((n & (n - 1)) != 0) {
            cout<<-1<<endl;
        } else {
            for (int i=0; i<(1<<n); i++) {
                int sum = 0;
                for (int j=0; j<n; j++) {
                    if ((1<<j)&i) {
                        sum ^= j;
                    }
                }
                c[i] = sum;
            }
            for (int i=0; i<(1<<n); i++) {
                ans[a[i]] = c[i];
            }
            for (int i=0; i<(1<<n); i++) {
                cout<<ans[i]<<" ";
            }
            cout<<endl;
        }
    }

    return 0;
}
