#include <iostream>
#include <vector>
#include <queue>

constexpr int N = 1 << 16;

int T, n;
bool vis[N], use[N];
std::vector<int> v[N];
int id[N], ans[N], c[N];
bool fail;

void bfs(int x) {
    std::queue<int> q;
    q.push(x);
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        if (vis[x]) continue;
        vis[x] = true;
        std::vector<int> a;
        for (int i : v[x])
            if (~id[i])
                a.push_back(id[i]);
        if (a.empty()) id[x] = 0;
        else {
            for (int j = 0; j < n; ++j) {
                int t = a[0] ^ (1 << j);
                if (use[t]) continue;
                bool ok = true;
                for (int k = 1; k < a.size(); ++k)
                    if (__builtin_popcount(t ^ a[k]) != 1) {
                        ok = false;
                        break;
                    }
                if (ok) { id[x] = t; break; }
            }
        }
        use[id[x]] = true;
        for (int i : v[x])
            if (!vis[i])
                q.push(i);
    }
}

int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
    std::cin >> T;
    while (T--) {
        std::cin >> n;
        for (int i = 0; i < 1 << n; ++i) v[i].clear(), vis[i] = use[i] = false, id[i] = -1;
        for (int i = 0, x, y; i < n << (n - 1); ++i) {
            std::cin >> x >> y;
            v[x].push_back(y);
            v[y].push_back(x);
        }
        bfs(0);
        for (int i = 0; i < 1 << n; ++i) ans[id[i]] = i;
        for (int i = 0; i < 1 << n; ++i) std::cout << ans[i] << ' ';
        std::cout << '\n';
        if (__builtin_popcount(n) == 1) {
            for (int i = 0; i < 1 << n; ++i) {
                c[ans[i]] = 0;
                for (int j = 0; j < n; ++j)
                    if (i & (1 << j))
                        c[ans[i]] ^= j;
            }
            for (int i = 0; i < 1 << n; ++i) std::cout << c[i] << ' ';
            std::cout << '\n';
        } else std::cout << "-1\n";
    }
    return 0;
}
