// https://codeforces.com/problemset/problem/1543/E

#include <bits/stdc++.h>
using namespace std;

constexpr int N = 16;
int n, m;
vector<vector<int>> e;
int a[1 << N][N];

void work() {
    cin >> n;
    e.clear();
    int n2 = 1 << n;
    e.resize(n2);
    m = n * (n2 / 2);
#ifndef ONLINE_JUDGE
    int rd = rand(), rc = 29;
    for (int x, y, i = 0; i < m * 2; ++i) {
        int p = i / n, q = i % n;
        x = p;
        y = x ^ (1 << q);
        x = (x * rc + rd) % n2;
        y = (y * rc + rd) % n2;
        e[x].push_back(y);
        int es = e[x].size();
        swap(e[x][es - 1], e[x][rand() % es]);
    }
#else
    for (int x, y, i = 0; i < m; ++i) {
        cin >> x >> y;
        e[x].push_back(y);
        e[y].push_back(x);
    }
#endif
    for (int i = 0; i < n2; ++i)
        for (int j = 0; j < n; ++j) a[i][j] = i ? -1 : e[0][j];

    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < (1 << i); ++j) {
            int x = 0;
            int y = a[x][i];
            a[y][i] = x;
            for (int k = 0; k < i; ++k)
                if (j >> k & 1) {
                    x = a[x][k];
                    if (a[y][k] >= 0)
                        y = a[y][k];
                    else {
                        int ny = 0;
                        // find e[y] that contains x
                        for (int z : e[y]) {
                            bool ok = true;
                            for (int p = 0; p <= i; ++p)
                                if (z == a[y][p]) {
                                    ok = false;
                                    break;
                                }
                            if (!ok) continue;
                            for (int z2 : e[z])
                                if (z2 == x) {
                                    ny = z;
                                    goto found;
                                }
                        }
                        assert(false);
                    found:
                        a[y][k] = ny;
                        a[ny][k] = y;
                        y = ny;

                        a[x][i] = y;
                        a[y][i] = x;
                    }
                }
        }
    }

    vector<int> c(n2, 0);
    for (int i = 0; i < n2; ++i) {
        int x = 0, y = 0;
        for (int j = 0; j < n; ++j)
            if (i >> j & 1) x = a[x][j], y ^= j;
        c[x] = y;
        cout << x << (i + 1 == n2 ? "\n" : " ");
    }

    if (!(n & (n - 1))) {
        for (int i = 0; i < n2; ++i) {
            cout << c[i] << (i + 1 == n2 ? "\n" : " ");
        }
    } else
        cout << "-1\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
    int tc = 1;
    /**/ cin >> tc;
    while (tc--) work();
    return 0;
}