//https://codeforces.com/problemset/problem/1543/E
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>

#define REP(token, num) for (token = 0; token < num; ++token)
#define REPI(token, num) for (int64_t token = 0; token < num; ++token)
#define REPIT(type, token, num) for (type token = 0; token < num; ++token)

#ifdef TESTING
#define DEBUG(...) __VA_ARGS__
#else
#define DEBUG(...)
#endif

typedef int64_t test_cases;
typedef int64_t vertex;
typedef int64_t num_vertices;
typedef int64_t num_edges;

vertex neighbors[65540][20], value[65540], invValue[65540];
num_vertices numNeighbors[65540];
bool addedToQueue[65540], processedInQueue[65540];

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    test_cases T;
    std::cin >> T;
    while (T--) {
        num_vertices N;
        std::cin >> N;
        std::fill(value, value+(1 << N), 0);
        std::fill(numNeighbors, numNeighbors+(1 << N), 0);
        std::fill(addedToQueue, addedToQueue+(1 << N), false);
        std::fill(processedInQueue, processedInQueue+(1 << N), false);
        
        num_edges numEdges = N*(1 << (N-1));
        REPI(i, numEdges) {
            vertex v1, v2;
            std::cin >> v1 >> v2;
            neighbors[v1][numNeighbors[v1]++] = v2;
            neighbors[v2][numNeighbors[v2]++] = v1;
        }

        vertex startVertex = 0;
        
        value[startVertex] = 0;
        addedToQueue[startVertex] = processedInQueue[startVertex] = true;
        std::queue<vertex> bfsQueue;
        REPI(i, N) {
            vertex curVertex = neighbors[startVertex][i];
            value[curVertex] = (1 << i);
            addedToQueue[curVertex] = processedInQueue[curVertex] = true;
            REPI(j, N) {
                vertex nextVertex = neighbors[curVertex][j];
                if (nextVertex != startVertex) {
                    value[nextVertex] |= value[curVertex];
                    bfsQueue.push(nextVertex);
                    addedToQueue[nextVertex] = true;
                }
            }
        }

        while (!bfsQueue.empty()) {
            vertex curVertex = bfsQueue.front();
            bfsQueue.pop();
            processedInQueue[curVertex] = true;

            REPI(i, N) {
                vertex nextVertex = neighbors[curVertex][i];
                if (!addedToQueue[nextVertex]) {
                    bfsQueue.push(nextVertex);
                    addedToQueue[nextVertex] = true;
                }
                if (!processedInQueue[nextVertex]) {
                    value[nextVertex] |= value[curVertex];
                }
            }
        }

        REPI(i, (1 << N)) invValue[value[i]] = i;
        REPI(i, (1 << N)) {
            std::cout << invValue[i];
            if (i+1 == (1 << N)) std::cout << "\n";
            else std::cout << " ";
        }

        int64_t exp2 = -1;
        if (N == 1) exp2 = 0;
        else if (N == 2) exp2 = 1;
        else if (N == 4) exp2 = 2;
        else if (N == 8) exp2 = 3;
        else if (N == 16) exp2 = 4;
        
        if (exp2 == -1) {
            std::cout << "-1\n";
        } else {
            REPI(i, (1 << N)) {
                vertex curVal = value[i];
                vertex curColor = 0;
                REPI(j, N) {
                    if ((curVal >> j) & 1) curColor ^= j;
                }
                std::cout << curColor;
                if (i+1 == (1 << N)) std::cout << "\n";
                else std::cout << " ";
            }
        }
    }

    return 0;
}
