Chef has an array A of length N and an integer X.

In one operation, Chef does the following:
Find the smallest element in the current array. Let this be S.
Next, pick any one index i such that A_{i} = S
Finally, replace A_{i} with A_{i} \oplus X

Here \oplus denotes the [bitwise XOR] operation.

For example, if A = [1, 1, 2] and X = 4, then in one move Chef can turn the array into either [5, 1, 2] or [1, 5, 2].

Chef performs this operation exactly Y times. Let B be final array obtained. 

Output the array B in sorted order. Note that under this restriction, the output is unique.

------ Input Format ------ 

- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains three space-separated integers N, X, and Y.
- The second line contains N space-separated integers denoting the array A.

------ Output Format ------ 

For each test case, output array B in sorted order.

------ Constraints ------ 

$1 ≤ T ≤ 10^{4}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ Y ≤ 10^{9}$
$1 ≤ A_{i} , X ≤ 2^{30}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.

----- Sample Input 1 ------ 
3
1 6 99
9
3 7 44
1 2 3
5 20 6
5 10 15 20 25

----- Sample Output 1 ------ 
15 
3 5 6 
5 20 25 27 30 

----- explanation 1 ------ 
Test case $1$: The array is initially $[9]$. Since there is only one element, it will be modified in each step. So,
- After the first operation, the array is $[15]$ (since $9 \oplus 6 = 15$)
- After the second operation, the array is $[9]$ (since $15 \oplus 6 = 9$)
- Continuing the above, it can be verified that after $99$ steps, the array is $[15]$.

Test case $3$: The sequence of steps is as follows:
- Initially, the array is $[5, 10, 15, 20, 25]$
- After operation $1$, it is $[17, 10, 15, 20, 25]$
- After operation $2$, it is $[17, 30, 15, 20, 25]$
- After operation $3$, it is $[17, 30, 27, 20, 25]$
- After operation $4$, it is $[5, 30, 27, 20, 25]$
- After operation $5$, it is $[17, 30, 27, 20, 25]$
- After operation $6$, it is $[5, 30, 27, 20, 25]$

Remember to print the output in sorted order.

Source: codechef | Difficulty: MEDIUM_HARD


Solutions:
for _ in range(int(input())):
	(N, X, Y) = list(map(int, input().split()))
	A = sorted(list(map(int, input().split())))
	xd = 0
	v = A[0] ^ X
	for i in range(N):
		if A[i] > v:
			break
		if A[i] ^ X <= A[i]:
			break
		v = min(v, A[i] ^ X)
		A[i] = A[i] ^ X
		xd += 1
		if xd == Y:
			break
	Y -= xd
	A = sorted(A)
	if Y % 2 == 0:
		print(*A)
	else:
		A[0] = A[0] ^ X
		print(*A)


import heapq as hq

def soln(n, x, y, arr):
	arr = [[arr[i], i] for i in range(n)]
	hq.heapify(arr)
	(ind, count) = (-1, -1)
	for ix in range(y):
		(cur, i) = hq.heappop(arr)
		hq.heappush(arr, [cur ^ x, i])
		if i == ind:
			count += 1
			if count > 3:
				if y - ix - 1 & 1:
					(cur, i) = hq.heappop(arr)
					hq.heappush(arr, [cur ^ x, i])
				break
		else:
			ind = i
			count = 0
	return sorted([i[0] for i in arr])
for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(*soln(n, x, y, arr))


for t in range(int(input())):
	(n, x, y) = [int(el) for el in input().split()]
	a = sorted([int(el) for el in input().split()])
	new = []
	currentmin = (float('inf'), -1)
	for (index, el) in enumerate(a):
		if el < currentmin[0] and y != 0:
			el ^= x
			new.append(el)
			currentmin = min((el, index), currentmin)
			y -= 1
		else:
			index -= 1
			break
	newarray = new + a[index + 1:]
	if y % 2 != 0:
		newarray[currentmin[1]] ^= x
	print(*sorted(newarray))


import heapq
for item in range(int(input())):
	(n, x, y) = map(int, input().split())
	arr = list(map(int, input().split()))
	heapq.heapify(arr)
	temp = y
	while y:
		if y == 0:
			break
		t = arr[0] ^ x
		if t < arr[0]:
			break
		heapq.heappop(arr)
		heapq.heappush(arr, t)
		y = y - 1
	if y % 2 != 0:
		t = arr[0] ^ x
		heapq.heappop(arr)
		heapq.heappush(arr, t)
	arr.sort()
	print(*arr, sep=' ')


import heapq as heap
try:
	n = int(input())
	for i in range(n):
		(n, x, t) = map(int, input().split())
		if n == 1:
			a = int(input())
			if t % 2 == 0:
				print(a)
			else:
				print(a ^ x)
		else:
			a = list(map(int, input().split()))
			heap.heapify(a)
			i = 0
			while i < t:
				b = heap.heappop(a)
				c = b ^ x
				heap.heappush(a, c)
				d = heap.heappop(a)
				i += 1
				if d == c:
					if (t - i) % 2 == 0:
						heap.heappush(a, d)
						break
					else:
						heap.heappush(a, b)
						break
				else:
					heap.heappush(a, d)
			a.sort()
			print(*a)
except:
	pass


from bisect import bisect_right
from collections import defaultdict
for _ in range(int(input())):
	(N, X, Y) = map(int, input().split())
	A = sorted(list(map(int, input().split())))
	(xor, ind) = (float('inf'), 0)
	for i in range(N):
		if Y == 0:
			break
		if xor <= A[i]:
			break
		tmp = A[i] ^ X
		if tmp < xor:
			xor = tmp
			ind = i
		A[i] = tmp
		Y -= 1
	if Y % 2:
		A[ind] ^= X
	A.sort()
	print(*A)


from bisect import bisect_right
from collections import defaultdict
for _ in range(int(input())):
	(N, X, Y) = map(int, input().split())
	A = sorted(list(map(int, input().split())))
	for j in range(Y):
		n = A.pop(0) ^ X
		i = bisect_right(A, n)
		if i == N - 1:
			A.append(n)
		else:
			A.insert(i, n)
		if i == 0:
			if (Y - j - 1) % 2:
				A[0] ^= X
			break
	print(*A)


from bisect import bisect_left
from code import interact
from heapq import heapify, heappush, heappop
from collections import deque
from pydoc import plain
import sys
from math import gcd, sqrt, log10, log2, floor, ceil, sqrt
input = sys.stdin.readline

def il():
	return [int(a) for a in input().strip().split()]

def ip():
	return input().strip()

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

def ot(in_p, *args, e=' '):
	if type(in_p) == list:
		print(*in_p, end=e)
	if type(in_p) == str or type(in_p) == int:
		print(in_p, end=e)
		for l in args:
			print(l, end=e)
	print()

def a_pwr_n(a, n, mod):
	if n == 1:
		return a % mod
	if n % 2 == 0:
		val = a_pwr_n(a, n // 2, mod)
		return val % mod * val % mod
	else:
		return a % mod * a_pwr_n(a, n - 1, mod) % mod

def rg(*ag):
	if len(ag) == 3:
		return range(ag[0], ag[1], ag[2])
	elif len(ag) == 2:
		return range(ag[0], ag[1])
	elif len(ag) == 1:
		return range(ag[0])
	else:
		raise 'invalid input'

def ispal(i, j, st):
	while i <= j:
		if st[i] == st[j]:
			i = i + 1
			j = j - 1
		else:
			return False
	return True
mod = 1000000000 + 7
dx = [-1, -2, 1, 2, 2, -2, -1, 1]
dy = [2, 1, 2, 1, -1, -1, -2, -2]
for _ in range(ii()):
	(N, A, B) = il()
	arr = il()
	m = []
	for j in arr:
		heappush(m, (j, False))
	for k in range(B):
		ele = heappop(m)
		if ele[1]:
			s = B - k
			if s % 2 == 0:
				heappush(m, ele)
			else:
				heappush(m, (ele[0] ^ A, True))
			break
		heappush(m, (ele[0] ^ A, True))
	ans = ''
	while m:
		ans += str(heappop(m)[0]) + ' '
	print(ans)


t = int(input())
for _ in range(t):
	(n, x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	l[0] ^= x
	m = l[0]
	count = 1
	for i in range(1, n):
		if l[i] >= m or count >= y:
			break
		l[i] ^= x
		m = min(l[i], m)
		count += 1
	l.sort()
	if (y - count) % 2:
		l[0] ^= x
	print(*l)


import heapq
for _ in range(int(input())):
	(n, x, y) = [int(temp) for temp in input().split()]
	a = {}
	a = [int(temp) for temp in input().split()]
	heapq.heapify(a)
	while y:
		min = x ^ a[0]
		if n == 1 or (n == 2 and min < a[1]) or (n > 2 and min < a[1] and (min < a[2])):
			break
		heapq.heappop(a)
		heapq.heappush(a, min)
		y -= 1
	if y % 2:
		a[0] = a[0] ^ x
	for i in range(0, n):
		print(heapq.heappop(a), end=' ')
	print()


def solve(N, X, Y, A):
	A.sort()
	A[0] ^= X
	mn = A[0]
	count = 1
	for i in range(1, N):
		if A[i] >= mn or count >= Y:
			break
		A[i] ^= X
		mn = min(A[i], mn)
		count += 1
	A.sort()
	if (Y - count) % 2:
		A[0] ^= X
	return A
for _ in range(int(input())):
	(N, X, Y) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	print(*solve(N, X, Y, A))


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	c = a[0] ^ x
	i = 1
	a[0] = a[0] ^ x
	while i < len(a) and c > a[i] and (i < y):
		a[i] = a[i] ^ x
		if a[i] < c:
			c = a[i]
		i += 1
	a.sort()
	if (y - i) % 2 != 0:
		a[0] = a[0] ^ x
	print(*a)


for _ in range(int(input())):
	(N, X, Y) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	operation_count = 1
	arr[0] = arr[0] ^ X
	minimum = arr[0]
	for i in range(1, N):
		if arr[i] < minimum and operation_count < Y:
			operation_count += 1
			arr[i] = arr[i] ^ X
			minimum = min(arr[i], minimum)
		else:
			break
	arr.sort()
	if (Y - operation_count) % 2 == 1:
		arr[0] = arr[0] ^ X
	print(*arr)


import bisect
r = int(input())
for _ in range(r):
	(n, x, y) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	c = 0
	while y > 0:
		t = arr[0] ^ x
		del arr[0]
		p = bisect.bisect_left(arr, t)
		if p == 0 or y == 1:
			if y % 2 == 0:
				t = t ^ x
				arr.insert(p, t)
				break
			else:
				arr.insert(p, t)
				break
		else:
			arr.insert(p, t)
			y -= 1
	print(*arr)


import bisect
for i in range(int(input())):
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	b.sort()
	while True:
		t = b[0] ^ a[1]
		del b[0]
		c = bisect.bisect_left(b, t)
		if c == 0 or a[2] - 1 == 0:
			if a[2] % 2 == 1:
				b.insert(c, t)
				break
			else:
				t = t ^ a[1]
				b.insert(c, t)
				break
		else:
			a[2] -= 1
			b.insert(c, t)
	print(*b)


import heapq

def main():
	import sys
	test_cases = int(sys.stdin.readline())
	for _ in range(test_cases):
		(_, X, Y) = (int(n) for n in sys.stdin.readline().strip().split())
		A = [int(n) for n in sys.stdin.readline().strip().split()]
		heapq.heapify(A)
		while Y:
			a = A[0]
			b = a ^ X
			if b < a:
				break
			else:
				heapq.heappop(A)
				heapq.heappush(A, b)
				Y -= 1
		if Y % 2 == 1:
			a = heapq.heappop(A)
			b = a ^ X
			heapq.heappush(A, b)
		A.sort()
		print(' '.join((str(a) for a in A)))
main()


def solve_test_case():
	(N, X, Y) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	A.sort()
	operation_count = 1
	A[0] = A[0] ^ X
	minimum = A[0]
	for i in range(1, N):
		if A[i] < minimum and operation_count < Y:
			operation_count += 1
			A[i] = A[i] ^ X
			minimum = min(A[i], minimum)
	A.sort()
	if (Y - operation_count) % 2 == 1:
		A[0] = A[0] ^ X
	print(*A)
T = int(input())
for _ in range(T):
	solve_test_case()


for i in range(int(input())):
	(n, x, y) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	a.sort()
	c = 1
	a[0] = a[0] ^ x
	m = a[0]
	for j in range(1, n):
		if a[j] < m and c < y:
			c += 1
			a[j] = a[j] ^ x
			m = min(a[j], m)
	a.sort()
	if (y - c) % 2 == 1:
		a[0] = a[0] ^ x
	print(*a)


import heapq as h

def insert(arr: list, x, low: int, high: int):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] <= x:
			if mid + 1 == len(arr) or arr[mid + 1] >= x:
				arr.insert(mid + 1, x)
			else:
				insert(arr, x, mid + 1, high)
		else:
			insert(arr, x, low, mid - 1)
	else:
		arr.insert(0, x)
t = int(input())
for _ in range(t):
	(n, x, y) = map(int, input().split(' '))
	if n == 1:
		a = int(input())
		print(a) if y % 2 == 0 else print(a ^ x)
	else:
		a = list(map(int, input().split(' ')))
		h.heapify(a)
		__ = 0
		while __ < y:
			b = h.heappop(a)
			xored = b ^ x
			h.heappush(a, xored)
			__ += 1
			c = h.heappop(a)
			if c == xored:
				if (y - __) % 2 == 0:
					h.heappush(a, c)
				else:
					h.heappush(a, b)
				break
			else:
				h.heappush(a, c)
		a.sort()
		print(*a)


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	a[0] ^= x
	minxor = a[0]
	j = 1
	while j < y and j < n and (minxor > a[j]):
		a[j] ^= x
		minxor = min(minxor, a[j])
		j += 1
	a.sort()
	if (y - j) % 2 == 1:
		a[0] = a[0] ^ x
	a.sort()
	print(*a)


from math import inf
from collections import *
import math, os, sys, heapq, bisect, random, threading
from functools import lru_cache
from itertools import *
import sys

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def inpu():
	return int(inp())

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())
(M, M1) = (1000000007, 998244353)

def main():
	how_much_noob_I_am = 1
	how_much_noob_I_am = inpu()
	for _ in range(how_much_noob_I_am):
		(n, x, y) = sep()
		arr = lis()
		arr.sort()
		xor = arr[0] ^ x
		if xor <= arr[0]:
			min1 = 0
		else:
			min1 = 0
			arr[0] = xor
			y -= 1
			for i in range(1, n):
				if y == 0:
					break
				if arr[i] >= xor:
					break
				p = arr[i] ^ x
				if p < xor:
					xor = p
					min1 = i
				arr[i] = p
				y -= 1
		if y % 2 != 0:
			arr[min1] = arr[min1] ^ x
		arr.sort()
		print(*arr)
main()


for _ in range(int(input())):
	(n, x, steps) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	a[0] ^= x
	minXor = a[0]
	step = 1
	while step < steps and step < n and (minXor > a[step]):
		a[step] ^= x
		minXor = min(minXor, a[step])
		step += 1
	a.sort()
	if (steps - step) % 2:
		a[0] ^= x
	print(*a)


t = int(input())
for _ in range(t):
	(n, x, y) = map(int, input().split())
	ali = list(map(int, input().split()))
	ali.sort()
	nm = ali[0] ^ x
	i = 1
	ali[0] = ali[0] ^ x
	while i < len(ali) and nm > ali[i] and (i < y):
		ali[i] = ali[i] ^ x
		if ali[i] < nm:
			nm = ali[i]
		i += 1
	ali.sort()
	if (y - i) % 2 != 0:
		ali[0] = ali[0] ^ x
	print(*ali)


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	num = list(map(int, input().split()))
	num.sort()
	co = 1
	small = num[0] ^ x
	num[0] = small
	for i in range(1, n):
		char = num[i]
		if char < small and co < y:
			co += 1
			num[i] = char ^ x
			small = min(char ^ x, small)
	num.sort()
	r = y - co
	if r % 2 == 1:
		num[0] = num[0] ^ x
	for i in range(n):
		print(num[i], end=' ')
	print('')


import bisect
t = int(input())
for t_1 in range(t):
	(n, x, y) = [int(item) for item in input().split(' ')]
	numbers = [int(item) for item in input().split(' ')]
	numbers = sorted(numbers)
	count_of_each_number = {}
	for num in numbers + [item ^ x for item in numbers]:
		if not count_of_each_number.__contains__(num):
			count_of_each_number[num] = 0
	for num in numbers:
		if not count_of_each_number.__contains__(num):
			count_of_each_number[num] = 0
		count_of_each_number[num] += 1
	all_nums = sorted(count_of_each_number.keys())
	index_Of_all = 0
	done_steps = 0
	while done_steps < y:
		while count_of_each_number[all_nums[index_Of_all]] == 0:
			index_Of_all += 1
		min_number = all_nums[index_Of_all]
		new_number = min_number ^ x
		reminded_y = y - done_steps
		if new_number < min_number:
			done_steps += reminded_y - reminded_y % 2
			doing_steps = reminded_y % 2
		else:
			doing_steps = min(reminded_y, count_of_each_number[min_number])
		count_of_each_number[min_number] -= doing_steps
		count_of_each_number[new_number] += doing_steps
		done_steps += doing_steps
	result = []
	for num in all_nums:
		for i in range(count_of_each_number[num]):
			result.append(num)
	print(' '.join([str(item) for item in result]))


from queue import PriorityQueue
t = int(input())
for _ in range(t):
	(n, x, y) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	q = PriorityQueue()
	for each in arr:
		q.put(each)
	while y:
		smallest = q.get()
		if smallest ^ x > smallest:
			q.put(smallest ^ x)
			y -= 1
		elif y & 1 == 0:
			q.put(smallest)
			break
		else:
			q.put(smallest ^ x)
			break
	while not q.empty():
		print(q.get(), end=' ')
	print()


from heapq import heappush, heappop, heapify

def solve(n, x, y, arr):
	h = [(num, i) for (i, num) in enumerate(arr)]
	heapify(h)
	seen = set()
	last = -1
	while y > 0:
		(num, i) = heappop(h)
		y -= 1
		heappush(h, (num ^ x, i))
		if i in seen:
			last = i
			break
		seen.add(i)
	if y % 2 == 1:
		arr[last] ^= x
	for i in seen:
		if i != last:
			arr[i] ^= x
	return ' '.join(map(str, sorted(arr)))
for _ in range(int(input())):
	(n, x, y) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	print(solve(n, x, y, arr))


t = int(input())
for _ in range(t):
	(n, x, y) = map(int, input().split())
	ls = list(map(int, input().split()))
	ls.sort()
	m = ls[0] ^ x
	c = 1
	ls[0] = m
	for i in range(1, n):
		ch = ls[i]
		if ls[i] < m and c < y:
			c += 1
			ls[i] = ch ^ x
			m = min(m, ch ^ x)
	ls.sort()
	r = y - c
	if r % 2 == 1:
		ls[0] = ls[0] ^ x
	print(*ls)


n = int(input())
for i in range(n):
	(N, X, Y) = (int(x) for x in input().split())
	ls = [int(x) for x in input().split()]
	ls.sort()
	count = 1
	mini = ls[0]
	small = mini ^ X
	ls[0] = small
	for i in range(1, N):
		ch = ls[i]
		if ch < small and count < Y:
			count = count + 1
			ls[i] = ch ^ X
			small = min(ch ^ X, small)
	ls.sort()
	r = Y - count
	if r % 2 == 1:
		ls[0] = ls[0] ^ X
	for i in ls:
		print(i, end=' ')
	else:
		print()


import heapq
from heapq import heappop, heappush, heapify
t = int(input())
for i in range(t):
	(N, X, Y) = map(int, input().strip().split())
	ls = list(map(int, input().strip().split()))
	heapq.heapify(ls)
	prev = -1
	while Y > 0:
		a = heapq.heappop(ls)
		val = a ^ X
		if val == prev:
			heapq.heappush(ls, a)
			break
		heapq.heappush(ls, val)
		prev = a
		Y -= 1
	if Y % 2 == 1:
		a = heapq.heappop(ls)
		val = a ^ X
		heapq.heappush(ls, val)
	ls.sort()
	for j in range(N):
		print(ls[j], end=' ')
	print()


from heapq import heapify, heappop, heappush
for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	heapify(a)
	for c in range(y):
		i = heappop(a)
		j = i ^ x
		if j <= i:
			if (y - c) % 2 == 0:
				j ^= x
			heappush(a, j)
			break
		heappush(a, j)
	l = [heappop(a) for _ in range(n)]
	print(*l)


def fib():
	[n, x, y] = list(map(int, input().split()))
	num = list(map(int, input().split()))
	num.sort()
	co = 1
	small = num[0] ^ x
	num[0] = small
	for i in range(1, n):
		char = num[i]
		if char < small and co < y:
			co += 1
			num[i] = char ^ x
			small = min(char ^ x, small)
	num.sort()
	r = y - co
	if r % 2 == 1:
		num[0] = num[0] ^ x
	print(' '.join((str(x) for x in num)))
n = int(input())
for i in range(n):
	fib()


import heapq
t = int(input())
while t:
	t -= 1
	(n, x, y) = map(int, input().split())
	arr = list(map(int, input().split()))
	heapq.heapify(arr)
	last = None
	while y:
		a = heapq.heappop(arr)
		if last == a:
			heapq.heappush(arr, a)
			break
		y -= 1
		last = a ^ x
		heapq.heappush(arr, a ^ x)
	arr.sort()
	if y % 2:
		arr[0] ^= x
	s = ''
	for a in arr:
		s += str(a)
		s += ' '
	print(s[:-1])


import heapq

def xoring(arr, X, Y, N):
	if N == 1:
		if Y % 2 == 0:
			return arr
		else:
			return [arr[0] ^ X]
	else:
		i = 0
		heapq.heapify(arr)
		while i < Y:
			smallest = heapq.heappop(arr)
			a = smallest ^ X
			heapq.heappush(arr, a)
			b = heapq.heappop(arr)
			i += 1
			if b == a:
				if (Y - i) % 2 == 0:
					heapq.heappush(arr, b)
					break
				else:
					heapq.heappush(arr, smallest)
					break
			else:
				heapq.heappush(arr, b)
		arr.sort()
		return arr
T = int(input())
for _ in range(T):
	(N, X, Y) = tuple(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort()
	print(*xoring(arr, X, Y, N))


class MinHeap(object):

	def __init__(self):
		self.size = 0
		self.root = 1
		self.heap = list()
		self.heap.append(-1)

	def _ensure_non_empty_heap(self):
		if self.size < self.root:
			raise RuntimeError('Empty heap')

	def _ensure_within_bounds(self, pos):
		if pos > self.size:
			raise RuntimeError('Position {0} is out of bounds of heap whose size is {1}'.format(pos, self.size))

	def _parent(self, pos):
		self._ensure_within_bounds(pos)
		return pos // 2

	def _left_child(self, pos):
		self._ensure_within_bounds(pos)
		return 2 * pos

	def _right_child(self, pos):
		self._ensure_within_bounds(pos)
		return 2 * pos + 1

	def _is_leaf(self, pos):
		self._ensure_within_bounds(pos)
		return 2 * pos > self.size

	def _swap(self, pos_a, pos_b):
		self._ensure_within_bounds(pos_a)
		self._ensure_within_bounds(pos_b)
		(self.heap[pos_a], self.heap[pos_b]) = (self.heap[pos_b], self.heap[pos_a])

	def _heapify(self, pos):
		if self.size == 0:
			return
		if self._is_leaf(pos):
			return
		left_child_pos = self._left_child(pos)
		right_child_pos = self._right_child(pos)
		if right_child_pos > self.size:
			if self.heap[left_child_pos] < self.heap[pos]:
				self._swap(pos, left_child_pos)
			return
		if self.heap[pos] <= min(self.heap[left_child_pos], self.heap[right_child_pos]):
			return
		if self.heap[left_child_pos] < self.heap[right_child_pos]:
			self._swap(pos, left_child_pos)
			self._heapify(left_child_pos)
		else:
			self._swap(pos, right_child_pos)
			self._heapify(right_child_pos)

	def insert(self, value):
		self.size += 1
		self.heap.append(value)
		index = self.size
		while self.heap[index] < self.heap[self._parent(index)]:
			self._swap(index, self._parent(index))
			index = self._parent(index)

	def pop(self):
		self._ensure_non_empty_heap()
		popped = self.heap[self.root]
		self._swap(self.root, self.size)
		self.size -= 1
		self._heapify(self.root)
		self.heap.pop()
		return popped

	def get_min(self):
		self._ensure_non_empty_heap()
		return self.heap[self.root]
T = int(input())
while T:
	T -= 1
	(N, X, Y) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	h = MinHeap()
	for a in A:
		h.insert(a)
	to_insert = -1
	while Y:
		heap_min = h.pop()
		heap_min_xor = heap_min ^ X
		if heap_min_xor < heap_min:
			if Y & 1:
				to_insert = heap_min_xor
			else:
				to_insert = heap_min
			break
		h.insert(heap_min_xor)
		Y -= 1
	if to_insert != -1:
		h.insert(to_insert)
	for i in range(N):
		cur = h.pop()
		print(cur, end=' ')
	print()


import heapq as h
for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	if n == 1:
		a = int(input())
		if y % 2 == 0:
			print(a)
		else:
			print(a ^ x)
	else:
		a = list(map(int, input().split()))
		h.heapify(a)
		i = 0
		while i < y:
			b = h.heappop(a)
			c = b ^ x
			h.heappush(a, c)
			d = h.heappop(a)
			i += 1
			if d == c:
				if (y - i) % 2 == 0:
					h.heappush(a, d)
					break
				else:
					h.heappush(a, b)
					break
			else:
				h.heappush(a, d)
		a.sort()
		print(*a)


def app(a, s, i, h):
	mid = (i + h) // 2
	if s <= a[0]:
		return 1
	if s >= a[h]:
		return h + 1
	if s >= a[mid] and s < a[mid + 1]:
		return mid + 1
	elif s > a[mid]:
		return app(a, s, mid + 1, h)
	else:
		return app(a, s, i, mid - 1)
t = int(input())
while t > 0:
	(n, x, y) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	if n == 1:
		if y % 2 == 0:
			print(a[0])
		else:
			print(a[0] ^ x)
		t = t - 1
		continue
	for i in range(y):
		if a[0] ^ x < a[1]:
			if (y - i) % 2 != 0:
				s = a[0] ^ x
			else:
				s = a[0]
			a[0] = s
			break
		else:
			s = a[0] ^ x
		k = app(a, s, 0, len(a) - 1)
		a.insert(k, s)
		a.remove(a[0])
	for x in a:
		print(x, ' ', end='')
	print('')
	t = t - 1


from heapq import heapify, heappush, heappop
t = int(input())
for _ in range(t):
	(n, x, y) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	repeat = dict()
	heap = arr[:]
	heapify(heap)
	cnt = 0
	for i in range(y):
		val = heap[0] ^ x
		if val in repeat.keys():
			break
		temp = heappop(heap)
		cnt += 1
		repeat[temp] = 1
		heappush(heap, temp ^ x)
	y = y - cnt
	if y % 2 == 1:
		temp = heappop(heap)
		heappush(heap, temp ^ x)
	heap.sort()
	for i in heap:
		print(i, end=' ')
	print()


import heapq as heap
try:
	num_of_cases = int(input())
	for _ in range(num_of_cases):
		(N, X, Y) = map(int, input().split(' '))
		A = list(map(int, input().split(' ')))
		if N == 1:
			if Y % 2 == 0:
				print(A[0])
			else:
				print(A[0] ^ X)
		else:
			heap.heapify(A)
			i = 0
			while i < Y:
				min = heap.heappop(A)
				xor = min ^ X
				heap.heappush(A, xor)
				new_min = heap.heappop(A)
				i += 1
				if xor == new_min:
					if (Y - i) % 2 == 0:
						heap.heappush(A, new_min)
						break
					else:
						heap.heappush(A, min)
						break
				else:
					heap.heappush(A, new_min)
			A.sort()
			print(*A)
except Exception:
	pass


import heapq as heap
t = int(input())
for i in range(t):
	(n, x, y) = map(int, input().split())
	if n == 1:
		A = int(input())
		if y % 2 == 0:
			print(A)
		else:
			print(A ^ x)
	else:
		A = list(map(int, input().split()))
		heap.heapify(A)
		for k in range(1, y + 1):
			s = heap.heappop(A)
			R = s ^ x
			heap.heappush(A, R)
			P = heap.heappop(A)
			if P == R:
				if (y - k) % 2 == 0:
					heap.heappush(A, P)
					break
				else:
					heap.heappush(A, s)
					break
			else:
				heap.heappush(A, P)
		A.sort()
		print(*A)


import heapq as hq
t = int(input())
cases = []
for u in range(t):
	cases.append([input().split(), input().split()])
for case in cases:
	N = int(case[0][0])
	X = int(case[0][1])
	Y = int(case[0][2])
	arr = [int(q) for q in case[1]]
	if len(arr) == 1:
		if Y & 1:
			print(arr[0] ^ X)
		else:
			print(arr[0])
	else:
		hq.heapify(arr)
		i = 0
		while i < Y:
			z1 = hq.heappop(arr)
			z2 = z1 ^ X
			hq.heappush(arr, z2)
			z3 = hq.heappop(arr)
			i += 1
			if z3 == z2:
				if not Y - i & 1:
					hq.heappush(arr, z3)
					break
				else:
					hq.heappush(arr, z1)
					break
			else:
				hq.heappush(arr, z3)
		arr.sort()
		for g in arr:
			print(g, end=' ')
		print('')


import heapq as hp
try:
	x = int(input())
	for i in range(x):
		(a, b, c) = map(int, input().split())
		if a == 1:
			d = int(input())
			if c % 2 == 0:
				print(d)
			else:
				print(b ^ d)
		else:
			l = list(map(int, input().split()))
			hp.heapify(l)
			i = 0
			while i < c:
				l1 = hp.heappop(l)
				y = l1 ^ b
				hp.heappush(l, y)
				l2 = hp.heappop(l)
				i += 1
				if y == l2:
					if (c - i) % 2 == 0:
						hp.heappush(l, l2)
						break
					else:
						hp.heappush(l, l1)
						break
				else:
					hp.heappush(l, l2)
			l.sort()
			print(*l)
except:
	pass


from heapq import heapify, heappop, heappush

def minimum(a, n):
	m = 1073741825
	midx = -1
	for i in range(n):
		if a[i] < m:
			m = a[i]
			midx = i
	return midx
t = int(input())
for i in range(t):
	(n, x, y) = [int(k) for k in input().split()]
	a = [int(k) for k in input().split()]
	if n == 1:
		if y % 2 != 0:
			print(a[0] ^ x)
		else:
			print(a[0])
		continue
	heapify(a)
	for j in range(y):
		b = heappop(a)
		c = b ^ x
		heappush(a, c)
		d = heappop(a)
		if c == d:
			if (y - j) % 2 == 0:
				heappush(a, b)
			else:
				heappush(a, d)
			break
		else:
			heappush(a, d)
	a.sort()
	for k in a:
		print(k, end=' ')
	print()


import heapq as heap
from secrets import choice
for _ in range(int(input())):
	(n, x, t) = map(int, input().split())
	if n == 1:
		a = int(input())
		if t % 2 == 0:
			print(a)
		else:
			print(a ^ x)
	else:
		a = list(map(int, input().split()))
		heap.heapify(a)
		i = 0
		while i < t:
			b = heap.heappop(a)
			c = b ^ x
			heap.heappush(a, c)
			d = heap.heappop(a)
			i += 1
			if d == c:
				if (t - i) % 2 == 0:
					heap.heappush(a, d)
					break
				else:
					heap.heappush(a, b)
					break
			else:
				heap.heappush(a, d)
		a.sort()
		print(*a)


import heapq as heap

def getanswer(l, m, n, k):
	heap.heapify(k)
	i = 0
	while i < n:
		q = heap.heappop(k)
		w = q ^ m
		heap.heappush(k, w)
		e = heap.heappop(k)
		i += 1
		if w == e:
			if (n - i) % 2 == 0:
				heap.heappush(k, e)
				break
			else:
				heap.heappush(k, q)
				break
		else:
			heap.heappush(k, e)
	k.sort()
	return print(*k)
t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().strip().split())
	if a == 1:
		r = int(input())
		if c % 2 == 0:
			print(r)
		else:
			print(r ^ b)
	else:
		nlist = list(map(int, input().strip().split()))
		getanswer(a, b, c, nlist)


t = int(input())
for i in range(t):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().strip().split()))[:n]
	b = sorted(a)
	u = y
	p = o = 0
	min = b[0] ^ x
	if n <= y:
		for j in range(n - 1):
			b[j] = b[j] ^ x
			u -= 1
			if min > b[j]:
				min = b[j]
				p = j
			if min <= b[j + 1]:
				break
			if j == n - 2:
				o = 1
	elif n > y:
		for j in range(y):
			b[j] = b[j] ^ x
			u -= 1
			if min > b[j]:
				min = b[j]
				p = j
			if min <= b[j + 1]:
				break
	if n <= y and u > 0 and (o == 1):
		b[n - 1] = b[n - 1] ^ x
		u -= 1
		if min > b[n - 1]:
			min = b[n - 1]
			p = n - 1
	if u % 2 == 1:
		b[p] = b[p] ^ x
	c = sorted(b)
	print(*c, sep=' ')


import heapq as heap
try:
	N = int(input())
	for i in range(N):
		(M, xIN, tES) = map(int, input().split())
		if M == 1:
			aI = int(input())
			if tES % 2 == 0:
				print(aI)
			else:
				print(aI ^ xIN)
		else:
			aI = list(map(int, input().split()))
			heap.heapify(aI)
			i = 0
			while i < tES:
				bB = heap.heappop(aI)
				cC = bB ^ xIN
				heap.heappush(aI, cC)
				dD = heap.heappop(aI)
				i += 1
				if dD == cC:
					if (tES - i) % 2 == 0:
						heap.heappush(aI, dD)
						break
					else:
						heap.heappush(aI, bB)
						break
				else:
					heap.heappush(aI, dD)
			aI.sort()
			print(*aI)
except:
	pass


import queue
for T in range(int(input())):
	(N, X, Y) = map(int, input().split())
	L = list(map(int, input().split()))
	P = queue.PriorityQueue()
	for v in L:
		P.put((v, 0))
	while Y > 0:
		(v, r) = P.get()
		newv = 0
		if r == 1:
			if Y % 2 == 0:
				newv = v
				Y = 0
			else:
				newv = v ^ X
				Y = 0
		else:
			newv = v ^ X
			Y -= 1
		P.put((newv, 1))
	newL = []
	while not P.empty():
		newL.append(P.get()[0])
	print(*newL)


import heapq as heap

def hello():
	print('HELLO')

def n():
	print('!23')

def check(N):
	print(*N)

def main(kk):
	for _ in range(kk):
		(q, w, e) = map(int, input().split())
		r = list(map(int, input().split()))
		if q == 1:
			if e % 2 != 0:
				print(r[0] ^ w)
				continue
			print(r[0])
			continue
		heap.heapify(r)
		i = 0
		while e > i:
			p = heap.heappop(r)
			a = p ^ w
			heap.heappush(r, a)
			k = heap.heappop(r)
			i += 1
			if k == a:
				if (e - i) % 2 == 0:
					heap.heappush(r, k)
					break
				elif (e - i) % 2 != 0:
					heap.heappush(r, p)
					break
			elif k != a:
				heap.heappush(r, k)
		r.sort()
		check(r)
		continue
main(int(input()))


import heapq
for _ in range(int(input())):
	(n, x, y) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	heapq.heapify(l)
	flag = 0
	for k in range(y):
		m = heapq.heappop(l)
		d = m ^ x
		heapq.heappush(l, d)
		e = heapq.heappop(l)
		if d == e:
			if (y - k) % 2 != 0:
				heapq.heappush(l, e)
				break
			else:
				heapq.heappush(l, e ^ x)
				break
		else:
			heapq.heappush(l, e)
	l.sort()
	print(*l)