#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target_tbl("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


//#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>
#include "random"
#include "chrono"
#include "cstring"


using namespace std;

#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);

/////////////////
#define endl '\n'
/////////////////

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;

//#define int unsigned int
#define int long long
#define double ld
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<vi> vvi;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

int xx[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int yy[8] = { 0, 0, 1, -1, -1, -1, 1, 1 };
string dir = "RDLU";
string travel = "ENWS";

const int N = 2e5 + 50, oo = 1e9 + 500;
//const int mod = 998244353;
const int mod = 1e9 + 7;
//const int mod = 1e9 + 9;
const int M2 = 1000000093, x2 = 27162;
const int M1 = 1000000087, x1 = 241;
const double eps = 1e-18, PI = 2 * acos(0.0);

vi check(vi &a, vi &b)
{
	int n = SZ(a);
	int m = SZ(b);

	vi c;
	int i = 0, j = 0;
	while(i < n)
	{
		if (j >= m)
			break;

		if (a[i] < b[j])
		{
			i++;
			continue;
		}

		if (a[i] == b[j])
		{
			c.push_back(a[i]);
			i++;
			j++;
			continue;
		}

		if (a[i] > b[j])
		{
			j++;
			continue;
		}
	}
	return c;
}

signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen("paintbarn.in", "r", stdin);
	//freopen("paintbarn.out", "w", stdout);

	int T;
	cin >> T;

	while (T--)
	{
		int n;
		cin >> n;

		vvi g(1 << n);
		for (int i = 0; i < n*(1 << (n - 1)); i++)
		{
			int u, v;
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}

		for (int i = 0; i < (1 << n); i++)
		{
			sort(all(g[i]));
		}		
		vi p(1 << n, -1);
		vi used(1 << n, 0);
		used[0] = 1;
		p[0] = 0;

		for (int i = 1; i < (1 << n); i++)
		{
			vi cur;
			int par = -1;
			for (int j = 0; j < n; j++)
			{
				int ii = i ^ (1 << j);
				if (p[ii] != -1)
				{
					par = p[ii];
					cur.push_back(p[ii]);
				}
			}

			sort(all(cur));

			for (int j: g[par]) //candidates
			{
				if (check(cur, g[j]) == cur && !used[j])
				{
					used[j] = 1;
					p[i] = j;
					break;
				}
			}
		}

		//cout << "!!! ";
		show(p);

		if (n != 1 && n != 2 && n != 4 && n != 8 && n != 16)
		{
			cout << -1 << endl;
			continue;
		}

		vi c(1 << n);
		for (int i = 0; i < (1 << n); i++)
		{
			int col = 0;
			for (int j = 0; j < n; j++)
			{
				if (i & (1 << j))
					col ^= j;
			}

			c[i] = col;
		}

		vi cc(1 << n);
		for (int i = 0; i < (1 << n); i++)
		{
			cc[p[i]] = c[i];
		}
		c = cc;

		show(c);
	}
}

