#include <bits/stdc++.h>
#define all_of(v) (v).begin(), (v).end()
using namespace std;

void BFS(int src, vector<int> &dist, const vector<vector<int>> &G) {
	queue<int> Q;
	fill(all_of(dist), -1);
	Q.push(src);
	dist[src] = 0;
	while (!Q.empty()) {
		int v = Q.front();
		Q.pop();
		for (int to : G[v]) {
			if (dist[to] == -1) {
				dist[to] = dist[v] + 1;
				Q.push(to);
			}
		}
	}
}

void solve() {
	int n;
	cin >> n;
	
	int vn = 1 << n, en = vn * n / 2;
	vector<vector<int>> G(vn);
	for (int i = 0; i < en; i++) {
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	vector<vector<int>> dist(n + 1, vector<int>(vn));
	BFS(0, dist[n], G);
	for (int i = 0; i < n; i++) {
		BFS(G[0][i], dist[i], G);
	}
	
	vector<int> P(vn), col(vn);
	for (int i = 0; i < vn; i++) {
		int id = 0;
		for (int j = 0; j < n; j++) {
			if (dist[j][i] < dist[n][i]) {
				id |= 1 << j;
			}
			if (i >> j & 1) {
				col[i] ^= j;
			}
		}
		P[id] = i;
	}
	
	vector<int> ans(vn);
	for (int i = 0; i < vn; i++) {
		ans[P[i]] = col[i];
	}
	
	for (int i = 0; i < vn; i++) {
		cout << P[i] << " \n"[i == vn - 1];
	}
	if (n & (n - 1)) {
		cout << "-1\n";
	}
	else {
		for (int i = 0; i < vn; i++) {
			cout << ans[i] << " \n"[i == vn - 1];
		}
	}
}

int main() {
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(0); cin.tie(0);

	int tc = 1;
	cin >> tc;
	for (int i = 1; i <= tc; i++) {
		solve();
	}

	return 0;
}