#include<bits/stdc++.h> usingnamespacestd; #define ll long long #ifndef ONLINE_JUDGE #define dbg(x...) do{cout << "\033[33;1m" << #x << "->" ; err(x);} while (0) voiderr(){cout << "\033[39;0m" << endl;} template<template<typename...> classT, typenamet, typename... A> voiderr(T<t> a, A... x){for (auto v: a) cout << v << ' '; err(x...);} template<typename T, typename... A> voiderr(T a, A... x){cout << a << ' '; err(x...);} #else #define dbg(...) #endif #define inf 1ll << 50 constint N = 1e5 + 5; constint maxn = N * 2 * 25; int tot; int ch[maxn][2]; int sum[maxn]; int root1, root2;
intnewnode() { tot++; for (int i = 0; i < 2; i++) ch[tot][i] = 0; sum[tot] = 0; return tot; } voidinsert(int root, int x) { int cur = root; for (int p = 29; p >= 0; p--) { int t = (x >> p) & 1; int u = ch[cur][t]; if (!u) { ch[cur][t] = newnode(); u = ch[cur][t]; } sum[cur]++; cur = u; } sum[cur]++; } int ans[N]; int cnt;
intquery(int u, int v, int tmp1, int tmp2) { if (!ch[u][0] && !ch[u][1]) { int s = min(sum[u], sum[v]); for (int i = 1; i <= min(sum[u], sum[v]); i++) ans[++cnt] = tmp1 ^ tmp2; sum[u] -= s; sum[v] -= s; //dbg(sum[u], sum[v], tmp1, tmp2); return s; } int s = 0; for (int i = 0; i < 2; i++) { if (exist(ch[u][i]) && exist(ch[v][i])) { //puts("same"); //dbg(tmp1, tmp2, i); int t = query(ch[u][i], ch[v][i], tmp1 << 1 | i, tmp2 << 1 | (i)); sum[u] -= t; sum[v] -= t; s += t; } } for (int i = 0; i < 2; i++) { if (exist(ch[u][i]) && exist(ch[v][!i])) { //puts("diff"); //dbg(tmp1, tmp2, i); int t = query(ch[u][i], ch[v][!i], tmp1 << 1 | i, tmp2 << 1 | (!i)); sum[u] -= t; sum[v] -= t; s += t; } } return s; } int a[N], b[N]; voidinit() { tot = 0; root1 = newnode(); root2 = newnode(); cnt = 0; } intmain() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); init(); for (int i = 1; i <= n; i++) insert(root1, a[i]); for (int i = 1; i <= n; i++) insert(root2, b[i]); assert(query(root1, root2, 0, 0) == n); sort(ans + 1, ans + n + 1); for (int i = 1; i <= n; i++) printf("%d%c", ans[i], i == n? '\n': ' '); } return0; }