Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.

You are given an odd integer $N$ and two integer sequences $A_{1}, A_{2}, \ldots, A_{N}$ and $B_{1}, B_{2}, \ldots, B_{N}$.

Your task is to reorder the elements of $B$, forming a new sequence $C_{1}, C_{2}, \ldots, C_{N}$ (i.e. choose a permutation $P_{1}, P_{2}, \ldots, P_{N}$ of the integers $1$ through $N$, where $C_{i} = B_{P_{i}}$ for each valid $i$), in such a way that the following condition holds: $(A_{1} \oplus C_{1}) = (A_{2} \oplus C_{2}) = \ldots = (A_{N} \oplus C_{N})$, where $\oplus$ denotes bitwise XOR. Find one such reordered sequence or determine that it is impossible.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
The third line contains $N$ space-separated integers $B_{1}, B_{2}, \ldots, B_{N}$.

------  Output ------
For each test case:
If there is no valid way to reorder the sequence $B$, print a single line containing the integer $-1$.
Otherwise, print a single line containing $N$ space-separated integers $C_{1}, C_{2}, \ldots, C_{N}$. If there are multiple solutions, you may find any one.

------  Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 10^{5}$
$N$ is odd
$0 ≤ A_{i} ≤ 10^{6}$ for each valid $i$
$0 ≤ B_{i} ≤ 10^{6}$ for each valid $i$

----- Sample Input 1 ------ 
1

5

3 1 2 4 5

2 4 5 1 3
----- Sample Output 1 ------ 
3 1 2 4 5

Source: codechef | Difficulty: HARD
Tags: Bit manipulation

Mathematics


Solutions:
import itertools
t = int(input())
for _ in range(t):
	N = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	ultimate_sum = 0
	for i in range(20):
		mask = 1 << i
		count_a = 0
		count_b = 0
		for (a, b) in zip(A, B):
			if a & mask > 0:
				count_a += 1
			if b & mask > 0:
				count_b += 1
		if count_a == 0 and count_b == 0:
			continue
		if count_a != count_b:
			ultimate_sum |= 1 << i
		elif N - count_a == count_b:
			print(-1)
			break
	perm = [a ^ ultimate_sum for a in A]
	if sorted(perm) != sorted(B):
		print(-1)
	else:
		print(' '.join(map(str, perm)))


import itertools
T = int(input())

def helper(A_rem, B_rem, ultimate_sum):
	a = A_rem[0]
	candidates = []
	index_B = []
	if len(A_rem) == 1:
		if a ^ B_rem[0] == ultimate_sum:
			return B_rem
		else:
			return -1
	for (i, b) in enumerate(B_rem):
		if a ^ b == ultimate_sum:
			candidates.append(b)
			index_B.append(i)
	if len(candidates) == 0:
		return -1
	for (i, c) in zip(index_B, candidates):
		result = helper(A_rem[1:], B_rem[:i] + B_rem[i + 1:], ultimate_sum)
		if result != -1:
			return [c] + result
	return -1
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	ultimate_sum = 0
	for i in range(20):
		mask = 1 << i
		count_a = 0
		count_b = 0
		for (a, b) in zip(A, B):
			if a & mask > 0:
				count_a += 1
			if b & mask > 0:
				count_b += 1
		if count_a == 0 and count_b == 0:
			continue
		if count_a != count_b:
			ultimate_sum |= 1 << i
		elif N - count_a == count_b:
			print(-1)
			break
	perm = [a ^ ultimate_sum for a in A]
	wrong = False
	if sorted(perm) != sorted(B):
		wrong = True
	if wrong:
		print(-1)
	else:
		print(' '.join(map(str, perm)))


def solve(a, b, n):
	ans = 0
	for i in range(n):
		ans ^= a[i] ^ b[i]
	for i in range(n):
		a[i] ^= ans
	if sorted(a) == sorted(b):
		return a
	return -1
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = solve(a, b, n)
	if ans == -1:
		print(-1)
	else:
		print(*ans)


def func(n, a, b):
	ans = 0
	for i in range(n):
		ans ^= a[i] ^ b[i]
	for i in range(n):
		a[i] ^= ans
	if sorted(a) == sorted(b):
		return a
	return -1
test = int(input().strip())
for i in range(test):
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	ans = func(n, a, b)
	if ans == -1:
		print(-1)
	else:
		for i in ans:
			print(i, end=' ')
		print()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = 0
	o = []
	for j in b:
		x ^= j
	for j in a:
		x ^= j
	for j in a:
		o.append(j ^ x)
	if sorted(o) == sorted(b):
		print(*o, end=' ')
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	xor = 0
	c = []
	for i in range(len(a)):
		xor = xor ^ a[i]
	for i in range(len(b)):
		xor = xor ^ b[i]
	for i in range(n):
		c.append(a[i] ^ xor)
	temp = list(c)
	temp.sort()
	b.sort()
	if b == temp:
		for i in range(len(c)):
			print(c[i], end=' ')
	else:
		print(-1)


T = int(input())
for i in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = 0
	for i in a:
		d ^= i
	for i in b:
		d ^= i
	res = []
	for i in a:
		res.append(i ^ d)
	if sorted(res) == sorted(b):
		print(*res)
	else:
		print(-1)


def answer():
	xor = 0
	for i in range(n):
		xor ^= a[i] ^ b[i]
	bc = [0] * (10 ** 6 + 1)
	for i in b:
		bc[i] += 1
	ans = []
	for v in a:
		if bc[v ^ xor]:
			ans.append(v ^ xor)
			bc[v ^ xor] -= 1
		else:
			return [-1]
	return ans
for T in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(*answer())


from collections import defaultdict
from sys import stdin, stdout
from math import *
from statistics import mode
from heapq import *

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p]:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def lcm(a, b):
	return a * b // gcd(a, b)

def prime_factors(n):
	(i, factors) = (2, [])
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return set(factors)

def prefix_arr(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def kadane(a):
	max_so_far = curr_max = a[0]
	for i in range(1, len(a)):
		curr_max = max(a[i], curr_max + a[i])
		max_so_far = max(max_so_far, curr_max)
	return max_so_far

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, ceil(sqrt(n)) + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def isPowerOf2(x):
	return x and (not x & x - 1)

def isPerfectSquare(n):
	return pow(floor(sqrt(n)), 2) == n

def I():
	return int(stdin.readline())

def S():
	return input()

def ari():
	return list(map(int, stdin.readline().split()))

def ars():
	return list(map(str, input().split()))

def mpi():
	return map(int, input().split())

def mps():
	return map(str, input().split())

def xor(arr):
	temp = 0
	for i in arr:
		temp ^= i
	return temp
for t in range(I()):
	N = I()
	A = ari()
	B = ari()
	Ci = xor(A) ^ xor(B)
	C = []
	for i in A:
		C.append(i ^ Ci)
	if sorted(C) == sorted(B):
		print(*C)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	xorsum = 0
	flag = 0
	for i in range(n):
		xorsum ^= a[i]
		xorsum ^= b[i]
	list1 = []
	for i in a:
		x = xorsum ^ i
		list1.append(x)
	list2 = sorted(list1)
	b.sort()
	if b == list2:
		print(*list1)
	else:
		print('-1')


def xorr(x):
	sum = 0
	for i in range(0, len(x)):
		sum ^= x[i]
	return sum
for _ in range(0, int(input())):
	xor3 = []
	count = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(list(map(int, input().split())))
	pxor = xorr(a) ^ xorr(b)
	if n % 2 != 0:
		for i in range(0, n):
			xor3.append(a[i] ^ pxor)
	else:
		for i in range(0, n):
			xor3.append(a[i] ^ 0)
	xor4 = sorted(xor3)
	for i in range(0, n):
		if xor4[i] == b[i]:
			count += 1
		else:
			print(-1)
			break
	if count == n:
		for i in range(0, count):
			print(xor3[i], end=' ')


try:
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		b_count = [0] * (10 ** 6 + 1)
		c = []
		xv = 0
		flag = 0
		for i in range(n):
			xv = xv ^ a[i]
		for i in range(n):
			xv = xv ^ b[i]
			b_count[b[i]] += 1
		for i in range(n):
			if b_count[a[i] ^ xv]:
				b_count[a[i] ^ xv] -= 1
				c.append(a[i] ^ xv)
			else:
				flag = 1
				break
		if flag == 1:
			print(-1, end='\n')
		else:
			for i in range(n):
				print(c[i], end=' ')
			print(end='\n')
except EOFError as e:
	print(end='')


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mapb = {}
	flag = 0
	for i in b:
		if i in mapb:
			mapb[i] += 1
		else:
			mapb[i] = 1
	temp = 0
	for i in a:
		temp ^= i
	for i in b:
		temp ^= i
	c = [i ^ temp for i in a]
	for i in c:
		if i in mapb:
			mapb[i] -= 1
		else:
			flag = 1
			break
	if flag:
		print(-1)
	else:
		print(*c)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = 0
	for i in a:
		x = x ^ i
	for i in b:
		x = x ^ i
	l = []
	for i in a:
		l.append(i ^ x)
	s1 = sorted(b)
	s2 = sorted(l)
	if s1 == s2:
		for i in l:
			print(i, end=' ')
	else:
		print(-1)
	print()


from sys import stdin, stdout
from math import gcd, log2, log10, floor
import math
from collections import defaultdict, OrderedDict
from bisect import bisect_left

def xora(l):
	res = 0
	for i in l:
		res ^= i
	return res

def listcreator(l, n):
	res = l[:]
	for i in range(len(res)):
		res[i] ^= n
	return res
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	theta = xora(a + b)
	c = listcreator(a, theta)
	bsort = b[:]
	bsort.sort()
	csort = c[:]
	csort.sort()
	if bsort == csort:
		print(*c)
	else:
		print(-1)


for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = list(map(int, input().split()))
	x = l[0]
	for i in l[1:]:
		x ^= i
	for j in d:
		x ^= j
	s = []
	for i in l:
		s.append(x ^ i)
	if sorted(s) == sorted(d):
		print(*s)
	else:
		print(-1)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	temp = a[0]
	for i in range(1, n):
		temp = temp ^ a[i]
	freq = {}
	for x in input().split():
		x = int(x)
		temp = temp ^ x
		if x in freq:
			freq[x] += 1
		else:
			freq[x] = 1
	ans = []
	for i in range(n):
		temp2 = temp ^ a[i]
		if temp2 in freq:
			freq[temp2] -= 1
			ans.append(temp2)
			if freq[temp2] == 0:
				del freq[temp2]
		else:
			print(-1)
			break
		if i == n - 1:
			for item in ans:
				print(item, end=' ')
			print()


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		b = li()
		x = 0
		m = dd(int)
		for i in a:
			x ^= i
		for i in b:
			x ^= i
			m[i] += 1
		ans = []
		f = 0
		for i in a:
			x1 = i ^ x
			if m[x1] > 0:
				m[x1] -= 1
				ans.append(x1)
			else:
				f = 1
				break
		if f:
			print('-1')
		else:
			print(*ans)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


t = int(input())
for _ in range(t):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	X = 0
	for i in A:
		X ^= i
	for i in B:
		X ^= i
	L = []
	for i in A:
		L.append(i ^ X)
	P = sorted(B[:])
	Q = sorted(L[:])
	if P == Q:
		for i in L:
			print(i, end=' ')
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	xor = a[0]
	for i in a[1:]:
		xor = xor ^ i
	for i in b:
		xor = xor ^ i
	perm = []
	for i in a:
		perm.append(i ^ xor)
	if sorted(perm) == sorted(b):
		print(*perm)
	else:
		print(-1)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l_1 = list(map(int, input().split()))
	l_2 = list(map(int, input().split()))
	x = 0
	for i in range(len(l_1)):
		x = x ^ l_1[i] ^ l_2[i]
	new = []
	for i in range(len(l_1)):
		t = x ^ l_1[i]
		new.append(t)
	new_1 = Counter(new)
	l_2 = Counter(l_2)
	flag = 0
	for i in new_1:
		if new_1[i] != l_2[i]:
			flag = 1
			break
	if flag == 1:
		print(-1)
	else:
		print(*new)


from functools import reduce
inp = lambda : map(int, input().split())
for _ in range(int(input())):
	N = int(input())
	A = list(inp())
	B = list(inp())
	av = {}
	x = reduce(lambda a, b: a ^ b, A + B)
	res = [0] * N
	for i in range(N):
		av[B[i]] = 1
	for i in range(N):
		res[i] = A[i] ^ x
		if av.get(res[i], 0):
			pass
		else:
			print(-1)
			break
	else:
		print(*res)


from functools import reduce
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = reduce(lambda x, y: x ^ y, a) ^ reduce(lambda x, y: x ^ y, b)
	c = []
	for i in a:
		c.append(i ^ x)
	b.sort()
	k = c.copy()
	k.sort()
	if b == k:
		print(*c)
	else:
		print(-1)


def creator(array1, array2):
	temp = 0
	for x in array1:
		temp ^= x
	for x in array2:
		temp ^= x
	array = [temp ^ a for a in array1]
	if sorted(array) == sorted(array2):
		return array
	return [-1]
testCases = int(input())
arrays1 = []
arrays2 = []
for _ in range(testCases):
	n = input()
	arrays1.append(list(map(int, input().split())))
	arrays2.append(list(map(int, input().split())))
for l in range(testCases):
	for z in creator(arrays1[l], arrays2[l]):
		print(z, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = 0
	res = []
	for i in range(n):
		x = x ^ b[i] ^ a[i]
	for i in range(n):
		res.append(a[i] ^ x)
	if sorted(b) == sorted(res):
		for ele in res:
			print(ele, end=' ')
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	liA = list(map(int, input().split()))
	liB = list(map(int, input().split()))
	x = 0
	res = []
	for i in range(n):
		x = x ^ liA[i] ^ liB[i]
	for i in range(n):
		res.append(liA[i] ^ x)
	if sorted(res) == sorted(liB):
		for ele in res:
			print(ele, end=' ')
		print(' ')
	else:
		print(-1)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = 0
	l = []
	for i in range(n):
		x ^= a[i]
	for i in range(n):
		x ^= b[i]
	for i in range(n):
		l.append(x ^ a[i])
	m = l.copy()
	l.sort()
	b.sort()
	if l == b:
		print(*m)
	else:
		print(-1)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	main_xor = 0
	for i in a:
		main_xor ^= i
	for i in b:
		main_xor ^= i
	temp = [0] * n
	for i in range(n):
		temp[i] = a[i] ^ main_xor
	b.sort()
	temp.sort()
	flag = 0
	for i in range(n):
		if temp[i] != b[i]:
			flag = 1
			break
	if flag == 1:
		print(-1)
	else:
		for i in range(n):
			print(a[i] ^ main_xor, end=' ')
		print('')


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = input().split()
	b = input().split()
	x = 0
	for i in range(0, n):
		a[i] = int(a[i])
		b[i] = int(b[i])
		x = x ^ a[i]
		x = x ^ b[i]
	c = []
	d = []
	for i in range(0, n):
		c.append(x ^ a[i])
		d.append(x ^ a[i])
	b.sort()
	c.sort()
	if b == c:
		for i in range(0, n):
			print(d[i], end=' ')
		print()
	else:
		print(-1)


test = int(input())
for _ in range(test):
	n = int(input())
	a = list([int(j) for j in input().split()])
	b = list([int(j) for j in input().split()])
	set1 = set(b)
	c = list()
	x = a[0]
	y = b[0]
	for j in range(1, n):
		x ^= a[j]
		y ^= b[j]
	x ^= y
	for j in range(n):
		c.append(x ^ a[j])
	set2 = set(c)
	if set2 != set1:
		print(-1)
	else:
		for j in c:
			print(j, end=' ')
		print()


from functools import reduce
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	g = reduce(lambda x, y: x ^ y, a + b)
	s = sum(b)
	c = list()
	for j in a:
		x = g ^ j
		c.append(x)
		s -= x
		if s < 0:
			break
	if s == 0:
		print(' '.join(map(str, c)))
	else:
		print(-1)


T = int(input())
for i in range(T):
	N = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	(s, t) = (a[0], b[0])
	for i in range(1, N):
		s = s ^ a[i]
		t = t ^ b[i]
	s = s ^ t
	c = [0 for i in range(N)]
	for i in range(N):
		c[i] = a[i] ^ s
	if sorted(c) == sorted(b):
		print(*c)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	(x, y) = (a[0], b[0])
	for i in range(1, n):
		x = x ^ a[i]
		y = y ^ b[i]
	x = x ^ y
	c = [0 for i in range(n)]
	for i in range(n):
		c[i] = a[i] ^ x
	if sorted(c) == sorted(b):
		print(*c)
	else:
		print(-1)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	xor = 0
	for x in a + b:
		xor ^= x
	cnt = Counter(b)
	ans = []
	for x in a:
		y = xor ^ x
		if cnt[y]:
			ans.append(y)
			cnt[y] -= 1
	if len(ans) == n:
		print(*ans)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	assert len(a) == n
	assert len(b) == n
	(x1, x2) = (0, 0)
	for i in a:
		x1 ^= i
	cnt = dict()
	for i in b:
		x2 ^= i
		if i in cnt:
			cnt[i] += 1
		else:
			cnt[i] = 1
	(x, fl) = (x1 ^ x2, 0)
	ans = list()
	for i in a:
		c_i = x ^ i
		if cnt.get(c_i, 0) == 0:
			fl = 1
			break
		ans.append(c_i)
		cnt[c_i] -= 1
	if fl:
		print('-1')
	else:
		print(*ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	m = max(b)
	bcount = [0] * (m + 1)
	for i in b:
		bcount[i] += 1
	xor = 0
	for i in range(len(a)):
		xor ^= a[i] ^ b[i]
	ans = []
	flag = 0
	for i in range(len(a)):
		x = a[i] ^ xor
		if x <= m and bcount[x] > 0:
			bcount[x] -= 1
			ans.append(x)
		else:
			flag = 1
			print(-1)
			break
	if flag == 0:
		print(*ans)


for _ in range(int(input())):
	(n, a, b, x, c) = (int(input()), list(map(int, input().split(' '))), list(map(int, input().split(' '))), 0, [])
	for i in a:
		x ^= i
	for i in b:
		x ^= i
	for i in a:
		c.append(i ^ x)
	print(*c) if sorted(c) == sorted(b) else print(-1)


T = int(input())
for i in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	x = 0
	c = []
	for i in range(N):
		x = x ^ A[i] ^ B[i]
	for i in range(N):
		c.append(x ^ A[i])
	if sorted(c) != sorted(B):
		print(-1)
	else:
		for i in c:
			print(i, end=' ')
		print(' ')


try:
	t = int(input())
	while t:
		s = 0
		n = int(input())
		l = list(map(int, input().split()))
		m = list(map(int, input().split()))
		x = []
		for i in range(n):
			s = s ^ l[i] ^ m[i]
		for i in range(n):
			x.append(l[i] ^ s)
		if sorted(x) != sorted(m):
			print(-1)
		else:
			for i in x:
				print(i, end=' ')
			print()
		t -= 1
except:
	pass


for _ in range(int(input())):
	n = int(input())
	x = 0
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	for i in range(n):
		x = x ^ l1[i] ^ l2[i]
	l3 = []
	for i in range(n):
		l3.append(x ^ l1[i])
	l4 = l3.copy()
	l5 = l2.copy()
	l4.sort()
	l5.sort()
	if l4 != l5:
		print(-1)
	else:
		for i in range(n):
			print(x ^ l1[i], end=' ')
		print()


from functools import reduce
for t in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	Acopy = A[0:]
	Bcopy = B[0:]
	A = reduce(lambda x, y: x ^ y, A)
	B = reduce(lambda x, y: x ^ y, B)
	x = A ^ B
	C = [Acopy[i] ^ x for i in range(n)]
	if sorted(C) == sorted(Bcopy):
		print(*C)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = 0.5
	axor = 0
	bxor = 0
	for i in a:
		axor = axor ^ i
	for i in b:
		bxor = bxor ^ i
	x = axor ^ bxor
	c = []
	for i in a:
		c.append(i ^ x)
	if sorted(b) == sorted(c):
		print(*c)
	else:
		print(-1)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	d = []
	temp = 0
	x = 0
	for i in range(n):
		x ^= a[i]
		x ^= b[i]
	for i in a:
		c.append(x ^ i)
	d = c.copy()
	d.sort()
	b.sort()
	for i in range(n):
		if b[i] != d[i]:
			temp = 1
			print('-1')
			break
	if temp == 0:
		for i in c:
			print(i, end=' ')
		print()
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	count = [0 for i in range(10 ** 6 + 1)]
	for i in range(n):
		ans = ans ^ a[i] ^ b[i]
		count[b[i]] += 1
	r = []
	flag = 0
	for i in range(n):
		c = a[i] ^ ans
		if count[c] > 0:
			count[c] -= 1
			r.append(c)
		else:
			flag = 1
			break
	if flag == 1:
		print(-1)
	else:
		print(*r)


for _ in range(int(input())):
	N = int(input())
	lisA = list(map(int, input().split()))
	lisB = list(map(int, input().split()))
	lis = []
	sol = []
	y = lisA[0] ^ lisB[0]
	for j in range(1, N):
		y = y ^ lisA[j] ^ lisB[j]
	z = max(lisB)
	for j in range(z + 1):
		lis.append(0)
	for j in lisB:
		lis[j] += 1
	for j in range(N):
		if lis[lisA[j] ^ y] != 0:
			sol.append(lisA[j] ^ y)
			lis[lisA[j] ^ y] -= 1
		else:
			break
	if len(sol) != N:
		print(-1)
	else:
		for i in sol:
			print(i, end=' ')
		print()


for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	z = x + y
	w = []
	a = z[0]
	for j in range(1, len(z)):
		a = a ^ z[j]
	for j in x:
		w.append(j ^ a)
	a = w.copy()
	y.sort()
	w.sort()
	if y == w:
		print(*a)
	else:
		print(-1)


from collections import defaultdict
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dct = defaultdict(int)
	for j in b:
		dct[j] += 1
	ans = 0
	for j in range(n):
		ans = ans ^ a[j] ^ b[j]
	s = [0 for j in range(n)]
	for j in range(n):
		s[j] = a[j] ^ ans
	for j in s:
		dct[j] -= 1
	flag = 1
	for j in dct:
		if dct[j] != 0:
			flag = 0
	if flag:
		print(*s)
	else:
		print(-1)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque
import bisect as bi
import heapq as hq

def I():
	return int(input())

def In():
	return map(int, input().split())

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def main():
	try:
		for _ in range(int(input())):
			n = I()
			a = list(In())
			b = list(In())
			t = 0
			for i in range(n):
				t ^= a[i] ^ b[i]
			c = []
			for x in a:
				c.append(x ^ t)
			z = c.copy()
			c.sort()
			b.sort()
			q = 0
			for i in range(n):
				if c[i] - b[i] != 0:
					q = 1
					break
			if q == 0:
				print(*z)
			else:
				print(-1)
	except:
		pass
M = 998244353
P = 1000000007
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = []
	X = 0
	for i in range(n):
		X ^= a[i] ^ b[i]
	for j in range(n):
		c.append(a[j] ^ X)
	e = sorted(c)
	p = sorted(b)
	for i in range(n):
		if e[i] != p[i]:
			print(-1)
			break
		else:
			print(c[i], end=' ')


from functools import *
T = int(input())
while T:
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(y) for y in input().split()]
	d1 = {}
	for i in range(n):
		if a[i] not in d1.keys():
			d1[a[i]] = 1
		else:
			d1[a[i]] += 1
	d2 = {}
	for i in range(n):
		if b[i] not in d2.keys():
			d2[b[i]] = 1
		else:
			d2[b[i]] += 1
	k = int(reduce(lambda x, y: x ^ y, a + b))
	l = []
	flag = 1
	for i in range(n):
		c = a[i] ^ k
		if c in d2.keys():
			l.append(c)
		else:
			flag = 0
			break
	if flag == 0:
		print(-1)
	else:
		for i in l:
			print(i, end=' ')
		print('\n')
	T -= 1


import copy
for _ in range(int(input())):
	n = int(input())
	xor = 0
	xor1 = 0
	d = []
	a = list(map(int, input().split()))
	c = list(map(int, input().split()))
	for i in range(n):
		xor = xor ^ a[i]
		xor1 = xor1 ^ c[i]
	xor2 = xor ^ xor1
	for i in range(n):
		d.append(a[i] ^ xor2)
	e = copy.deepcopy(d)
	c.sort()
	e.sort()
	if e == c:
		print(*d)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	xor = 0
	for j in range(n):
		xor = xor ^ a[j] ^ b[j]
	c = []
	z = []
	for j in range(n):
		c.append(xor ^ a[j])
		z.append(xor ^ a[j])
	counter = 0
	b.sort()
	c.sort()
	for j in range(n):
		if c[j] == b[j]:
			continue
		else:
			counter = -1
			break
	if counter == -1:
		print(-1)
	else:
		for k in range(n):
			print(z[k], end=' ')


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = []
	solution = True
	Bdict = defaultdict(bool)
	for x in B:
		Bdict[x] = True
	xor = 0
	for i in range(n):
		xor = xor ^ B[i] ^ A[i]
	for i in range(n):
		C.append(A[i] ^ xor)
	if sorted(B) == sorted(C):
		print(*C)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = [int(s) for s in input().split()]
	b = [int(s) for s in input().split()]
	ans = 0
	for i in a:
		ans = ans ^ i
	for i in b:
		ans = ans ^ i
	c = []
	for i in range(len(a)):
		c.append(a[i] ^ ans)
	b.sort()
	c.sort()
	flag = True
	for i in range(len(b)):
		if b[i] != c[i]:
			flag = False
			break
	if flag:
		for i in a:
			print(i ^ ans, end=' ')
		print()
	else:
		print(-1)


def main():
	t = int(input())
	for i in range(1, t + 1):
		go()

def go():
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	k = 0
	string = ''
	c = []
	for i in range(len(a)):
		k ^= a[i]
		k ^= b[i]
	for i in range(len(a)):
		c += [k ^ a[i]]
	d = sorted(b)
	e = sorted(c)
	if d == e:
		for i in range(len(c)):
			string += str(c[i]) + ' '
		string[::-1]
		print(string)
	else:
		print(-1)
main()


for _ in range(int(input())):
	n = int(input())
	(l1, l2) = ([int(i) for i in input().split()], [int(i) for i in input().split()])
	xor = 0
	for i in range(n):
		xor ^= l1[i] ^ l2[i]
	ans = [l1[i] ^ xor for i in range(len(l1))]
	if sorted(ans) == sorted(l2):
		print(*ans)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	(l1, l2) = ([int(i) for i in input().split()], [int(i) for i in input().split()])
	initial1 = l1[0]
	initial2 = l2[0]
	for i in range(1, n):
		xor1 = initial1 ^ l1[i]
		xor2 = initial2 ^ l2[i]
		initial1 = xor1
		initial2 = xor2
	xor = xor1 ^ xor2
	ans = [l1[i] ^ xor for i in range(len(l1))]
	if sorted(ans) == sorted(l2):
		print(*ans)
	else:
		print(-1)


from collections import Counter
import math
t = int(input())
for _ in range(t):
	n = int(input())
	ls1 = list(map(int, input().strip().split()))
	ls2 = list(map(int, input().strip().split()))
	val1 = 0
	for val in ls1:
		val1 ^= val
	for val in ls2:
		val1 ^= val
	c = [0] * n
	for i in range(n):
		c[i] = ls1[i] ^ val1
	ls2.sort()
	c.sort()
	f = 0
	for i in range(n):
		if c[i] != ls2[i]:
			f = 1
	if f:
		print('-1')
	else:
		ans = []
		for i in range(n):
			ans.append(ls1[i] ^ val1)
		print(*ans)


t = int(input())
while t > 0:
	c = []
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans1 = a[0]
	ans2 = b[0]
	for i in range(1, len(a)):
		ans1 = ans1 ^ a[i]
	for i in range(1, len(b)):
		ans2 = ans2 ^ b[i]
	answer = ans1 ^ ans2
	finalanswer = answer
	for i in range(0, len(a)):
		c.append(finalanswer ^ a[i])
	if sorted(c) == sorted(b):
		print(*c, end=' ')
	else:
		print('-1')
	t -= 1


try:
	t = int(input())
	for s in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		x = 0
		for val in a:
			x = x ^ val
		for val in b:
			x = x ^ val
		c = []
		for i in range(n):
			c.append(a[i] ^ x)
		c.sort()
		b.sort()
		f = 0
		for i in range(n):
			if c[i] != b[i]:
				f = 1
				break
		if f != 1:
			for i in range(n):
				print(a[i] ^ x, end=' ')
		else:
			print(-1)
except:
	pass


from sys import stdin, stdout
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = []
	c = []
	fre = [0] * max(b)
	for i in b:
		fre[i - 1] = 1
	for i in range(n):
		c.append(a[i] ^ b[i])
	x = c[0]
	for i in range(1, n):
		x ^= c[i]
	for i in range(n):
		flag = 0
		if fre[(x ^ a[i]) - 1] == 1:
			flag = 1
			d.append(x ^ a[i])
		if flag == 0:
			print('-1')
			break
	if i == n - 1:
		for k in d:
			print(k, end=' ')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	for j in a:
		c = c ^ j
	for j in b:
		c = c ^ j
	l = []
	for j in range(n):
		l.append(c ^ a[j])
	d = l.copy()
	l.sort()
	b.sort()
	if b == l:
		for j in d:
			print(j, end=' ')
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res = a[0] ^ b[0]
	for i in range(1, n):
		res ^= a[i] ^ b[i]
	l = []
	for i in range(n):
		l.append(a[i] ^ res)
	l2 = sorted(l)
	b.sort()
	f = 1
	for i in range(n):
		if b[i] != l2[i]:
			f = 0
			break
	if f == 0:
		print(-1)
	else:
		for i in range(n):
			print(l[i], end=' ')
		print()


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	X = 0
	C = [0] * N
	for I in range(N):
		X ^= A[I] ^ B[I]
	for I in range(N):
		C[I] = A[I] ^ X
	if sorted(B) == sorted(C):
		print(' '.join(map(str, C)))
	else:
		print(-1)


ts = int(input())
while ts > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	xor = 0
	for i in range(n):
		xor ^= a[i]
		xor ^= b[i]
	s = {}
	for i in b:
		if i in s:
			s[i] += 1
		else:
			s[i] = 1
	flag = True
	ans = []
	for i in a:
		if xor ^ i in s:
			s[xor ^ i] -= 1
			if s[xor ^ i] == 0:
				s.pop(xor ^ i)
			ans.append(xor ^ i)
		else:
			flag = not flag
			break
	if flag:
		print(' '.join(map(str, ans)))
	else:
		print(-1)
	ts -= 1


for _ in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	(arr3, arr4) = ([], [])
	(x1, x2) = (0, 0)
	for i in range(len(arr2)):
		x1 ^= arr1[i]
		x2 ^= arr2[i]
	arr2.sort()
	for i in range(len(arr1)):
		arr3.append(arr1[i] ^ (x1 ^ x2))
		arr4.append(arr3[-1])
	arr3.sort()
	if arr2 == arr3:
		for i in range(len(arr4)):
			print(arr4[i], end=' ')
	else:
		print('-1')


for tc in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	y = a[0] ^ b[0]
	for i in range(1, n):
		y ^= a[i] ^ b[i]
	b.sort()
	c = []
	for i in range(n):
		c.append(a[i] ^ y)
	d = c.copy()
	d.sort()
	if d != b:
		print(-1)
	else:
		print(*c)


from collections import defaultdict
from functools import reduce
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	xor = reduce(lambda i, j: i ^ j, a + b)
	d = defaultdict(int)
	for i in b:
		d[i] += 1
	ans = []
	for i in a:
		if xor ^ i not in d or d[xor ^ i] == 0:
			print(-1)
			break
		ans.append(xor ^ i)
		d[xor ^ i] -= 1
	else:
		print(*ans)


t = int(input())
while t != 0:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c1 = 0
	for i in range(len(a)):
		c1 = c1 ^ a[i] ^ b[i]
	c = list()
	for i in range(len(a)):
		c.append(c1 ^ a[i])
	if sorted(c) == sorted(b):
		for i in c:
			print(i, end=' ')
	else:
		print('-1', end='')
	print()


t = int(input())
for z in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	x = 0
	flag = 0
	visit = [0] * 10 ** 6
	new_arr = []
	for i in range(n):
		x = x ^ A[i]
	for k in range(n):
		x = x ^ B[k]
		visit[B[k]] += 1
	for j in range(n):
		val = A[j] ^ x
		visit[val] -= 1
		new_arr.append(val)
		if visit[val] < 0:
			flag = -1
			print(-1)
			break
	if flag != -1:
		print(*new_arr)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	xor = 0
	for x in range(n):
		xor = xor ^ a[x] ^ b[x]
	ans = []
	for j in a:
		ans.append(j ^ xor)
	fans = list(ans)
	ans.sort()
	b.sort()
	if ans == b:
		print(*fans)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l4 = l1.copy()
	a = 0
	for i in l1:
		a = a ^ i
	for i in l2:
		a = a ^ i
	l3 = [0] * n
	for i in range(n):
		l3[i] = a ^ l2[i]
	l3.sort()
	l4.sort()
	f = 0
	for i in range(n):
		if l3[i] != l4[i]:
			f = 1
			break
	if f:
		print(-1)
	else:
		for i in range(n):
			print(a ^ l1[i], end=' ')
		print(end='\n')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	xtemp = 0
	for i in range(n):
		xtemp = xtemp ^ a[i] ^ b[i]
	c = []
	for i in range(n):
		c.append(xtemp ^ a[i])
	if sorted(c) == sorted(b):
		print(*c)
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d_b = dict()
	for x in b:
		if x in d_b:
			d_b[x] += 1
		else:
			d_b[x] = 1
	a_xor = 0
	b_xor = 0
	for i in a:
		a_xor ^= i
	for i in b:
		b_xor ^= i
	ans = a_xor ^ b_xor
	b = True
	st_ans = ''
	for i in a:
		v = i ^ ans
		if v in d_b:
			if d_b[v] > 0:
				st_ans += str(v) + ' '
				d_b[v] -= 1
			else:
				b = False
				break
		else:
			b = False
			break
	if b:
		print(st_ans.strip())
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	xor = a[0]
	for i in range(1, n):
		xor ^= a[i]
	for i in range(n):
		xor ^= b[i]
	c = []
	for i in range(n):
		c.append(a[i] ^ xor)
	b.sort()
	temp = list(c)
	temp.sort()
	temp = str(temp)
	b = str(b)
	if temp == b:
		print(' '.join(map(str, c)))
	else:
		print(-1)


def find(A, B):
	temp = 0
	for x in A:
		temp ^= x
	for x in B:
		temp ^= x
	C = [temp ^ a for a in A]
	if sorted(C) == sorted(B):
		return C
	return [-1]
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().strip().split()))
	B = list(map(int, input().strip().split()))
	print(*find(A, B))


t = int(input())
for i in range(t):
	n = int(input())
	A = [int(j) for j in input().split()]
	B = [int(j) for j in input().split()]
	pk = 0
	for i in A:
		pk = pk ^ i
	for i in B:
		pk = pk ^ i
	ans = []
	d = {}
	for i in B:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	for i in A:
		a = i ^ pk
		if a in d:
			if d[a] > 0:
				d[a] -= 1
				ans.append(a)
			else:
				print(-1)
				break
		else:
			print(-1)
			break
	else:
		for i in ans:
			print(i, end=' ')
		print()