A sequence of non-negative integers $a_1, a_2, \dots, a_n$ is called growing if for all $i$ from $1$ to $n - 1$ all ones (of binary representation) in $a_i$ are in the places of ones (of binary representation) in $a_{i + 1}$ (in other words, $a_i \:\&\: a_{i + 1} = a_i$, where $\&$ denotes bitwise AND ). If $n = 1$ then the sequence is considered growing as well.

For example, the following four sequences are growing:

$[2, 3, 15, 175]$ — in binary it's $[10_2, 11_2, 1111_2, 10101111_2]$;

$[5]$ — in binary it's $[101_2]$;

$[1, 3, 7, 15]$ — in binary it's $[1_2, 11_2, 111_2, 1111_2]$;

$[0, 0, 0]$ — in binary it's $[0_2, 0_2, 0_2]$.

The following three sequences are non-growing:

$[3, 4, 5]$ — in binary it's $[11_2, 100_2, 101_2]$;

$[5, 4, 3]$ — in binary it's $[101_2, 100_2, 011_2]$;

$[1, 2, 4, 8]$ — in binary it's $[0001_2, 0010_2, 0100_2, 1000_2]$.

Consider two sequences of non-negative integers $x_1, x_2, \dots, x_n$ and $y_1, y_2, \dots, y_n$. Let's call this pair of sequences co-growing if the sequence $x_1 \oplus y_1, x_2 \oplus y_2, \dots, x_n \oplus y_n$ is growing where $\oplus$ denotes bitwise XOR .

You are given a sequence of integers $x_1, x_2, \dots, x_n$. Find the lexicographically minimal sequence $y_1, y_2, \dots, y_n$ such that sequences $x_i$ and $y_i$ are co-growing.

The sequence $a_1, a_2, \dots, a_n$ is lexicographically smaller than the sequence $b_1, b_2, \dots, b_n$ if there exists $1 \le k \le n$ such that $a_i = b_i$ for any $1 \le i < k$ but $a_k < b_k$.


-----Input-----

The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.

The first line of each test case contains an integer $n$ ($1 \le n \le 2 \cdot 10^5$) — length of the sequence $x_i$.

The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i < 2^{30}$) — elements of the sequence $x_i$.

It is guaranteed that the sum of $n$ overall all test cases doesn't exceed $2 \cdot 10^5$.


-----Output-----

For each test case, print $n$ integers $y_1, y_2, \dots, y_n$ ($0 \le y_i < 2^{30}$) — lexicographically minimal sequence such that such that it's co-growing with given sequence $x_i$.


-----Examples-----

Input
5
4
1 3 7 15
4
1 2 4 8
5
1 2 3 4 5
4
11 13 15 1
1
0
Output
0 0 0 0 
0 1 3 7 
0 1 0 3 2 
0 2 0 14 
0


-----Note-----

None

Difficulty: EASY
Tags: Bit manipulation

Constructive algorithms

Greedy algorithms
Skill types: Bit manipulation

Greedy algorithms

Starter code:

Solutions:
def main():
	n = int(input())
	x = list(map(int, input().split()))
	y = [0]
	for i in range(1, n):
		newx = x[i - 1] | x[i]
		y.append(newx ^ x[i])
		x[i] = newx
	print(*y)
	return
t = int(input())
for _ in range(t):
	main()


t = int(input())
for i in range(t):
	n = int(input())
	x = [int(x) for x in input().split()]
	xored = [x[0]]
	y = ['0']
	for j in range(n - 1):
		k = xored[j] | x[j + 1]
		k -= x[j + 1]
		y.append(str(k))
		xored.append(x[j + 1] ^ k)
	separator = ' '
	print(separator.join(y))


def read_ints():
	return [int(x) for x in input().split()]
t = int(input())
for i in range(t):
	n = int(input())
	a = read_ints()
	res = [0]
	for i in range(1, n):
		res.append(~a[i] & a[i - 1])
		a[i] ^= res[-1]
	print(' '.join([str(x) for x in res]))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = [0]
	for i in range(1, n):
		s.append(a[i] & a[i - 1] ^ a[i - 1])
		a[i] ^= a[i] & a[i - 1] ^ a[i - 1]
	print(*s)


def f(x, y):
	return x & ~y
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0] * n
	for i in range(1, n):
		ans[i] = f(ans[i - 1] ^ a[i - 1], a[i])
	print(' '.join(map(str, ans)))


count = int(input())

def growing(a, b):
	return a & b == a
for _ in range(count):
	_ = input()
	seq = [int(x) for x in input().split(' ')]
	yseq = [0]
	prev = seq[0]
	for i in range(len(seq) - 1):
		b = prev & (seq[i + 1] ^ prev)
		yseq.append(b)
		prev = seq[i + 1] ^ b
	print(' '.join([str(x) for x in yseq]))


import sys, os.path
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	last = a[0]
	if n == 1:
		print(0)
		continue
	print(0, end=' ')
	for i in range(n - 1):
		v = (last ^ a[i + 1]) & last
		print(v, end=' ')
		last = v ^ a[i + 1]
	print()


ff = []
for i in range(31):
	ff.append(2 ** i)
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [0]
	for i in range(1, n):
		f = 0
		for j in ff:
			if arr[i - 1] & j != 0 and arr[i] & j == 0:
				f += j
		ans.append(f)
		arr[i] ^= ans[i]
	print(*ans)


def minCo_growingSequenceWith(array):
	(sequence, prevValue) = ('', 0)
	for value in array:
		n = prevValue & (prevValue ^ value)
		prevValue = value ^ n
		sequence += f' {n}'
	return sequence[1:]

def testCase_1547d():
	input()
	return map(int, input().split(' '))
tuple((print(minCo_growingSequenceWith(testCase_1547d())) for x in range(int(input()))))


import math, bisect, heapq, sys
p = [1]
for i in range(32):
	p.append(p[i] * 2)
for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = [0]
	for i in range(1, n):
		x = a[i - 1]
		y = a[i]
		z = 0
		ind = 0
		while x:
			if x % 2 and y % 2 == 0:
				z += p[ind]
			x //= 2
			y //= 2
			ind += 1
		ans.append(z)
		a[i] = a[i] ^ z
	print(*ans)


from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import ceil, log
setrecursionlimit(10 ** 7)
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	ans = [0]
	prev = arr[0]
	for i in range(1, n):
		sol = prev & ~arr[i]
		ans.append(sol)
		prev = sol ^ arr[i]
	print(*ans)


def minCo_growingSequenceWith(array):
	(sequence, prevValue) = ([], 0)
	for value in array:
		n = prevValue & (prevValue ^ value)
		prevValue = value ^ n
		sequence.append(n)
	return ' '.join(map(str, sequence))

def testCase_1547d():
	input()
	return map(int, input().split(' '))
for x in range(int(input())):
	print(minCo_growingSequenceWith(testCase_1547d()))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	dp = [0 for i in range(n)]
	for i in range(1, n):
		dp[i] = (dp[i - 1] ^ l[i - 1]) & ~l[i]
	print(' '.join(map(str, dp)))


t = int(input())
for _ in range(t):
	input()
	x_list = list(map(int, input().split()))
	y_list = [0]
	for i in range(1, len(x_list)):
		y_list.append(~x_list[i] & (x_list[i - 1] ^ y_list[i - 1]))
	print(*y_list)


import atexit, io, sys, collections, math, heapq, fractions, copy, os, functools
import sys
import random
import collections
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def f(ais):
	r = [0 for _ in range(len(ais))]
	for i in range(1, len(ais)):
		ai = ais[i]
		cur = 0
		prev = r[i - 1] ^ ais[i - 1]
		for j in range(32):
			if prev >> j & 1:
				if ai >> j & 1 == 0:
					cur += 1 << j
		r[i] = cur
	return r
for _ in range(int(input())):
	n = int(input())
	ais = list(map(int, input().split()))
	print(' '.join(map(str, f(ais))))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	pred = 0
	for x in a:
		print((x | pred) - x, end=' ')
		pred = x | pred
	print()


from math import log

def convert(n, m):
	b = []
	c = []
	while m:
		b.append(m % 2)
		m //= 2
	while n:
		c.append(n % 2)
		n //= 2
	z = []
	for i in range(len(b)):
		if b[i] == 1 and i < len(c) and (c[i] == 0):
			z.append(1)
		elif b[i] == 1 and i >= len(c):
			z.append(1)
		else:
			z.append(0)
	ans = 0
	z.reverse()
	for i in range(len(z)):
		if z[i] == 0:
			ans *= 2
		else:
			ans *= 2
			ans += 1
	return ans
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0]
	for i in range(1, len(a)):
		if a[i] & a[i - 1] == a[i - 1]:
			c.append(0)
			continue
		c.append(convert(a[i], a[i - 1]))
		a[i] ^= c[-1]
	for i in range(len(c)):
		print(c[i], end=' ')
	print()


from typing import List

def find_y_seq(len_x: int, x_seq: List[int]) -> None:
	ans = [0] * len_x
	ans[0] = x_seq[0]
	y_seq = [0] * len_x
	for i in range(1, len_x):
		y_seq[i] = (ans[i - 1] | x_seq[i]) ^ x_seq[i]
		ans[i] = x_seq[i] ^ y_seq[i]
	print(' '.join((str(v) for v in y_seq)))
num_of_cases = int(input())
for i in range(num_of_cases):
	n = int(input())
	x = [int(i) for i in input().split()]
	find_y_seq(n, x)


import collections
import math
import sys
from functools import reduce
import decimal
sys.setrecursionlimit(10 ** 9)
decimal.getcontext().rounding = decimal.ROUND_HALF_UP
graphDict = collections.defaultdict
queue = collections.deque()

class Graphs:

	def __init__(self):
		self.graph = graphDict(list)

	def add_edge(self, u, v):
		self.graph[u].append(v)

	def dfs_utility(self, nodes, visited_nodes):
		visited_nodes.add(nodes)
		for neighbour in self.graph[nodes]:
			if neighbour not in visited_nodes:
				self.dfs_utility(neighbour, visited_nodes)
			else:
				return neighbour

	def dfs(self, node):
		Visited = set()
		self.dfs_utility(node, Visited)

	def bfs(self, node):
		visited = set()
		if node not in visited:
			queue.append(node)
			visited.add(node)
		while queue:
			parent = queue.popleft()
			print(parent)
			for item in self.graph[parent]:
				if item not in visited:
					queue.append(item)
					visited.add(item)

def rounding(n):
	return int(decimal.Decimal(f'{n}').to_integral_value())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def inp():
	return sys.stdin.readline().strip()

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))
for _ in range(int(inp())):
	x = int(inp())
	arr = list_inp(int)
	if x == 1:
		print(0)
	else:
		first = arr[0]
		answer = [0]
		for item in arr[1:]:
			if item & first == first:
				first = item
				answer.append(0)
			else:
				num = (item | first) ^ item
				answer.append(num)
				first = num ^ item
		print(*answer)


for input_number in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0]
	c = [a[0]]
	for i in range(1, n):
		b.append((c[i - 1] | a[i]) - a[i])
		c.append(c[i - 1] | a[i])
	print(' '.join(map(str, b)))


for i in range(int(input())):
	input()
	res = 0
	for x in map(int, input().split()):
		res |= x
		print(x ^ res, end=' ')


from __future__ import division, print_function
import math
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	l = inlt()
	s = [0 for i in range(n)]
	for i in range(1, n):
		n1 = list(reversed(bin(l[i])[2:]))
		n2 = list(reversed(bin(l[i - 1])[2:]))
		v2 = len(n1)
		val = 0
		for j in range(len(n2)):
			if j < v2 and n2[j] == '1' and (n1[j] == '0'):
				val += 2 ** j
			elif j >= v2 and n2[j] == '1':
				val += 2 ** j
		s[i] = val
		l[i] = l[i] ^ val
	print(*s)


def process(A):
	n = len(A)
	answer = [0 for i in range(n)]
	A2 = [bin(x)[2:] for x in A]
	m = max([len(x) for x in A2])
	A2 = [x.zfill(m) for x in A2]
	for i in range(m):
		has_one = A2[0][i] == '1'
		for j in range(1, n):
			if A2[j][i] == '0' and has_one:
				answer[j] += 2 ** (m - 1 - i)
			elif A2[j][i] == '1':
				has_one = True
	return answer
t = int(input())
for i in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	print(' '.join(map(str, process(A))))


from sys import stdin
input = stdin.readline
rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
for _ in range(rn()):
	n = rn()
	a = rl()
	ans = [0]
	for i in range(1, n):
		add = a[i - 1] - (a[i] & a[i - 1])
		ans.append(add)
		a[i] += add
	print(*ans)


import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(sys.stdin.readline())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def myceil(x, y):
	return (x + y - 1) // y

def countBits(p, v):
	s = []
	while v and p:
		if v % 2 == p % 2:
			s.append('0')
		else:
			s.append('0' if v % 2 else '1')
		v = v // 2
		p = p // 2
	while p:
		s.append(str(p % 2))
		p = p // 2
	if len(s) == 0:
		s = ['0']
	return int(''.join(list(reversed(s))), 2)

def Solution(arr, n):
	res = [0]
	for i in range(1, n):
		res.append(countBits(res[-1] ^ arr[i - 1], arr[i]))
	print(*res)

def main():
	for _ in range(get_int()):
		n = get_int()
		arr = get_ints_in_list()
		Solution(arr, n)
main()


def solve(n, ar):
	seq = [0]
	res = [ar[0]]
	for i in range(1, n):
		x = (res[i - 1] ^ ar[i]) & res[i - 1]
		seq.append(x)
		res.append(seq[i] ^ ar[i])
	return seq
t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	print(' '.join((str(x) for x in solve(n, ar))))


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		x = list(map(int, input().split()))
		ans = [0]
		for i in range(1, n):
			a = x[i - 1] ^ x[i - 1] & x[i]
			x[i] ^= a
			ans.append(a)
		print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def solution(s):
	print(0, end=' ')
	a = s[0]
	for i in range(1, len(s)):
		a = a | s[i]
		curr = a ^ s[i]
		print(curr, end=' ')
		a = curr ^ s[i]
	print()
n = int(input())
for i in range(n):
	input()
	a = list(map(int, input().split()))
	solution(a)


def f(x, y):
	return x & ~y

def solve():
	n = int(input())
	t = list(map(int, input().split()))
	ans = [0 for _ in range(n)]
	for i in range(1, n):
		ans[i] = f(ans[i - 1] ^ t[i - 1], t[i])
	print(*ans)
tests = int(input())
for _ in range(tests):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(0)
		continue
	ans = [0]
	for i in range(1, n):
		ab = '{0:0b}'.format(a[i - 1])
		bb = '{0:0b}'.format(a[i])
		if len(ab) > len(bb):
			bb = '0' * (len(ab) - len(bb)) + bb
		else:
			ab = '0' * (len(bb) - len(ab)) + ab
		tmp = ''
		for k in range(len(ab)):
			if ab[k] == '1':
				tmp += '1'
			elif ab[k] == '0' and bb[k] == '1':
				tmp += '1'
			elif ab[k] == '0' and bb[k] == '0':
				tmp += '0'
		ans.append(a[i] ^ int(tmp, 2))
		a[i] = int(tmp, 2)
	print(*ans)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
MOD = 10 ** 9 + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	for _ in range(int(input())):
		n = int(input())
		a = [*map(int, input().split())]
		ans = [0]
		for i in range(1, n):
			x = a[i - 1] ^ a[i - 1] & a[i]
			a[i] ^= x
			ans.append(x)
		print(*ans)
main()


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
from bisect import bisect_left as lower_bound, bisect_right as upper_bound

def so():
	return int(input())

def st():
	return input()

def mj():
	return map(int, input().strip().split(' '))

def msj():
	return map(str, input().strip().split(' '))

def le():
	return list(map(int, input().split()))

def lebe():
	return list(map(int, input()))

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()

def joro(L):
	return ''.join(map(str, L))

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def tr(n):
	return n * (n + 1) // 2

def main():
	import math as my
	for i in range(so()):
		m = so()
		L = le()
		P = []
		for i in range(m):
			P.append(0)
		P[0] = 0
		a = L[0]
		for i in range(1, m, 1):
			c = 0
			for j in range(30):
				if a & 2 ** j != 0:
					if not L[i] & 2 ** j != 0:
						c += 2 ** j
			P[i] = c
			a = L[i] ^ P[i]
		print(*P)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())

def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [0] * n
	for i in range(1, n):
		pr = a[i - 1] ^ b[i - 1]
		b[i] = a[i] & pr ^ pr
	print(*b)
for tt in range(t):
	solve()


t = int(input())
for g in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	y = [0]
	for i in range(1, n):
		prev = x[i - 1] ^ y[i - 1]
		curr = prev & ~x[i]
		y.append(curr)
	print(*y)


import sys
input = sys.stdin.readline

def solve(a, b):
	a = bin(a)[2:]
	b = bin(b)[2:]
	a = '0' * (32 - len(a)) + a
	b = '0' * (32 - len(b)) + b
	s = ''
	for i in range(32):
		if a[i] == '1' and b[i] == '0':
			s += '1'
		else:
			s += '0'
	return int(s, 2)
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0]
	if n == 1:
		print(*ans)
		continue
	ans.append(solve(a[0], a[1]))
	for i in range(2, n):
		ans.append(solve(ans[-1] ^ a[i - 1], a[i]))
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0]
	binary = []
	for i in a:
		binary.append(bin(i)[2:])
	temp = ''
	z = 0
	for i in range(1, n):
		if a[i] & a[i - 1] == a[i - 1]:
			ans.append(0)
		else:
			prev = binary[i - 1]
			curr = binary[i]
			j = len(prev) - 1
			k = len(curr) - 1
			temp = ''
			if a[i - 1] <= a[i]:
				while j >= 0 and k >= 0:
					if prev[j] == '1' and curr[k] == '0':
						temp += '1'
					else:
						temp += '0'
					j -= 1
					k -= 1
			else:
				while j >= 0 and k >= 0:
					if prev[j] == '1' and curr[k] == '0':
						temp += '1'
					else:
						temp += '0'
					j -= 1
					k -= 1
				while j >= 0:
					temp += prev[j]
					j -= 1
			temp = temp[::-1]
			z = int(temp, 2)
			ans.append(z)
			a[i] = a[i] ^ z
			binary[i] = bin(a[i])[2:]
	print(*ans)


import sys
N = int(200000.0 + 5)
sys.setrecursionlimit(N)

def charming():
	n = int(input())
	x = list(map(int, input().split()))
	Xor = 0
	for i in range(len(x)):
		if i == 0:
			print(0, end=' ')
		else:
			print(Xor ^ Xor & x[i], end=' ')
		Xor = x[i] | x[i] ^ Xor
	print()
for t in range(int(input())):
	charming()


from math import sqrt, ceil, floor
import sys
from collections import Counter, deque
from collections import defaultdict as dd

def foo(x):
	x = 0
t = int(input())
for tt in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	y = [0]
	ans = [x[0]]
	for i in range(1, n):
		z = ans[i - 1] & x[i]
		z ^= ans[i - 1]
		y.append(z)
		ans.append(x[i] ^ y[i])
	print(*y)


from math import log2

def f1(x):
	y = int(log2(x)) + 1
	ans = ''
	while x > 0:
		if x >= 2 ** y:
			ans += '1'
			x -= 2 ** y
		else:
			ans += '0'
		y -= 1
	return ans
for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = [0]
	ans = [x[0]]
	for j in range(1, n):
		q = x[j]
		w = ans[j - 1] | q
		ans.append(w)
		yi = q ^ w
		y.append(yi)
	print(*y)


import heapq, math
from collections import defaultdict, deque
from os import getcwd
import sys, os.path
if os.path.exists('D:\\CP\\programs\\input.txt'):
	sys.stdout = open('D:\\CP\\programs\\output.txt', 'w')
	sys.stdin = open('D:\\CP\\programs\\input.txt', 'r')
input = sys.stdin.readline
test = int(input())
for _ in range(test):
	n = int(input())
	arr = list(map(int, input().split()))
	res = [0] * n
	for i in range(1, n):
		prevn = arr[i - 1] ^ res[i - 1]
		prev = bin(arr[i - 1] ^ res[i - 1])[2:]
		curb = bin(arr[i])[2:]
		s = ''
		for j in range(max(len(curb), len(prev))):
			if prevn >> j & 1 == 1:
				if arr[i] >> j & 1 == 0:
					s = '1' + s
				else:
					s = '0' + s
			else:
				s = '0' + s
		res[i] = int(s, 2)
	print(*res)


from sys import stdin, stdout
from heapq import heapify, heappush, heappop
import sys
from collections import Counter
from copy import deepcopy
import math
sys.setrecursionlimit(10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

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

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

def strinput():
	return stdin.readline().strip()

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

def intinput():
	return int(stdin.readline().strip())
for test in range(intinput()):

	def solve():
		n = intinput()
		arr = listinput()
		ans = [0]
		for i in range(n - 1):
			sol = 0
			ele1 = arr[i]
			ele = arr[i + 1]
			po = 0
			while ele1:
				if ele1 % 2 == 1:
					if ele % 2 == 0:
						sol += pow(2, po)
				ele1 = ele1 >> 1
				ele = ele >> 1
				po += 1
			ans.append(sol)
			arr[i + 1] = arr[i + 1] ^ sol
		return ans
	print(*solve())


import os
import sys
import math
import collections
import functools
import itertools
import heapq
import bisect
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcde'
MOD = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def INT():
	return int(input())

def STR():
	return input()

def INTs():
	return tuple(map(int, input().split()))

def ARRINT():
	return [int(i) for i in input().split()]

def ARRSTR():
	return [i for i in input().split()]
for _ in range(INT()):
	n = INT()
	arr = ARRINT()
	res = [0]
	for i in range(1, n):
		tmp = arr[i - 1] ^ arr[i - 1] & arr[i]
		arr[i] ^= tmp
		res += [tmp]
	print(*res)


for t in range(int(input())):
	n = int(input())
	xarr = list(map(int, input().split()))
	y = [0]
	for i in range(n - 1):
		xarr[i] = xarr[i] ^ y[i]
		req = (xarr[i] ^ xarr[i + 1]) & xarr[i]
		y.append(req)
	sy = [str(i) for i in y]
	print(' '.join(sy))


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	print(0, end=' ')
	c = a[0]
	for i in range(1, n):
		c |= a[i]
		print(c - a[i], end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = [0]
	k = l[0]
	for i in l[1:]:
		d = ~i & k
		l1.append(d)
		k = d ^ i
	print(*l1)


t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	y = [0] * n
	ans = [x[0]] * n
	for i in range(1, n):
		y[i] = (ans[i - 1] | x[i]) ^ x[i]
		ans[i] = x[i] ^ y[i]
	print(' '.join(map(str, y)))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ans = [0]
	pre = ar[0]
	for i in range(1, n):
		tem = 0
		st = 1
		while st <= pre:
			if st & pre and (not st & ar[i]):
				tem += st
			st <<= 1
		ans.append(tem)
		pre = ar[i] ^ tem
	print(*ans)


import sys
_DEBUG = False
if _DEBUG:
	fd = open('input.txt', 'r')
	sys.stdin = fd
for t in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	x = list(map(int, sys.stdin.readline().split()))
	y = [0]
	for i in range(1, n):
		y.append(~x[i] & x[i - 1])
		x[i] ^= y[i]
	print(*y)


from collections import Counter

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

def si():
	return input()

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

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

def li():
	return list(mi())
t = ii()
for _ in range(t):
	n = ii()
	a = li()
	res = [0]
	prev = a[0]
	for i in range(1, n):
		if prev & a[i] == prev:
			res.append(0)
			prev = a[i]
		else:
			temp = ''
			pr = bin(prev).replace('0b', '')
			ai = bin(a[i]).replace('0b', '')
			if len(pr) < len(ai):
				pr = '0' * (len(ai) - len(pr)) + pr
			else:
				ai = '0' * (len(pr) - len(ai)) + ai
			for j in range(len(pr)):
				if pr[j] == '1':
					if ai[j] == '1':
						temp += '0'
					else:
						temp += '1'
				else:
					temp += '0'
			res.append(int(temp, 2))
			prev = a[i] ^ res[-1]
	print(*res)


t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	y = [0 for _ in range(n)]
	cur = x[0]
	for i in range(1, n):
		if cur & x[i] == cur:
			cur |= x[i]
			continue
		y[i] = cur & ~x[i]
		cur |= x[i]
	print(*y)


import sys
from math import cos, pi, ceil, pi, tan, floor, gcd, sqrt, log2, factorial, log10
from collections import Counter
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase
from statistics import mean, median, mode
alpha = ascii_lowercase
beta = ascii_uppercase

def nextPowerOf2(n):
	p = 1
	if n and (not n & n - 1):
		return n
	while p < n:
		p <<= 1
	return p

def get_Divisors(n):
	arr = []
	i = 1
	while i <= sqrt(n):
		if n % i == 0:
			if n / i == i:
				arr.append(i)
			else:
				arr.append(i)
				arr.append(n // i)
		i = i + 1
	return arr

def isprime(n):
	if n == 1:
		return 0
	i = 2
	while i * i <= n:
		if n % i == 0:
			return 0
		i += 1
	return 1

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

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def main():
	for ttt in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		ans = [0]
		last = arr[0] ^ ans[-1]
		for j in range(1, n):
			res = 0
			for i in range(31):
				if 1 << i & last >= 1:
					if 1 << i & arr[j] == 0:
						res += 1 << i
			ans.append(res)
			last = arr[j] ^ ans[-1]
		print(*ans)
main()


import sys
import collections
import bisect
import time
import random
from itertools import permutations
import string
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
two = set()
for i in range(1, 32):
	two.add(2 ** i)
for t in range(int(input())):
	n = int(input())
	arr = get_list()
	ans = [0]
	for i in range(1, n):
		prev = bin(arr[i - 1] ^ ans[-1])[2:]
		binary = bin(arr[i])[2:]
		if len(prev) < len(binary):
			prev = '0' * (len(binary) - len(prev)) + prev
		else:
			binary = '0' * (len(prev) - len(binary)) + binary
		xor = ''
		for (left, right) in zip(prev, binary):
			if left == '0':
				xor += '0'
			elif left == right:
				xor += '0'
			else:
				xor += '1'
		xor = int(xor, 2)
		ans.append(xor)
	print(*ans)


def solve():
	n = int(input())
	a = [int(s) for s in input().split(' ')]
	res = 0
	ans = []
	for i in range(n):
		res |= a[i]
		ans.append(res ^ a[i])
	print(*ans)
t = int(input())
for _ in range(t):
	solve()


import sys
from os import path
if path.exists('Input.txt'):
	sys.stdin = open('Input.txt', 'r')
	sys.stdout = open('Output.txt', 'w')
input = lambda : sys.stdin.readline().rstrip()
from collections import deque

def solve_tc():
	n = int(input())
	ans = [0]
	tt = [0]
	l1 = list(map(int, input().split()))
	for i in range(1, n):
		ans.append(~(~(ans[-1] ^ l1[i - 1]) | l1[i]))
	return ' '.join(map(str, ans))
t = int(input())
for _ in range(t):
	sys.stdout.write(str(solve_tc()) + '\n')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0]
	for i in range(1, n):
		x = 0
		for j in range(0, 32):
			bas = 1 << j
			if bas & a[i - 1] != 0 and bas & a[i] == 0:
				x |= bas
		a[i] ^= x
		ans.append(x)
	print(*ans)


import sys

def match(a, b):
	return a ^ b & a

def solve(args, numargs):
	res = [0]
	last = args[0]
	for arg in args[1:]:
		res.append(match(last, arg))
		last = arg ^ res[-1]
	return ' '.join((str(r) for r in res))
num = sys.stdin.readline()
for n in range(int(num)):
	numargs = sys.stdin.readline()
	args = tuple((int(x) for x in sys.stdin.readline().split()))
	sys.stdout.write(solve(args, numargs))
	sys.stdout.write('\n')


import os
import sys
from io import BytesIO, IOBase
from math import log2
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def scanf(datatype=str):
	return datatype(sys.stdin.readline().rstrip())

def printf(answer=''):
	return sys.stdout.write(str(answer) + '\n')

def prints(answer):
	return sys.stdout.write(str(answer) + ' ')

def map_input(datatype=str):
	return map(datatype, sys.stdin.readline().split())

def list_input(datatype=str):
	return list(map(datatype, sys.stdin.readline().split()))

def testcase(number: int, solve_function):
	for _ in range(number):
		solve_function()

def solve():
	n = scanf(int)
	arr = list_input(int)
	mask = [0]
	for i in range(1, n):
		prev = arr[i - 1] ^ mask[i - 1]
		curr = arr[i]
		add = 0
		for j in range(30):
			num = 1 << j
			if num & prev:
				if curr & num == 0:
					add += num
		mask.append(add)
	for i in mask:
		prints(i)
	printf()
t = scanf(int)
testcase(t, solve)


def minCo_growingSequenceWith(array):
	(sequence, prevValue) = ('0', array[0])
	for value in array[1:]:
		if prevValue & value != prevValue:
			n = prevValue & (prevValue ^ value)
			prevValue = value ^ n
			sequence += f' {n}'
		else:
			prevValue = value
			sequence += ' 0'
	return sequence

def testCase_1547d():
	input()
	return tuple(map(int, input().split(' ')))
testCases = (testCase_1547d() for x in range(int(input())))
tuple((print(minCo_growingSequenceWith(testCase)) for testCase in testCases))


from collections import defaultdict, deque
t = int(input())
for _ in range(t):
	x = int(input())
	arr = list(map(int, input().split(' ')))
	ans = [0]
	prev = arr[0]
	for i in range(1, x):
		tmp = 0
		for j in range(31, -1, -1):
			if prev & 1 << j:
				if arr[i] & 1 << j == 0:
					tmp |= 1 << j
		ans.append(tmp)
		prev = arr[i] ^ tmp
	print(*ans)


t = int(input())
for i in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	y = [0]
	for j in range(1, n):
		prev = x[j - 1] ^ y[j - 1]
		new = prev & x[j] ^ prev
		y.append(new)
	print(*y)


t = int(input())
p = [1 for x in range(35)]
for i in range(1, 35):
	p[i] = p[i - 1] * 2
while t:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [0 for x in range(n)]
	for i in range(n - 1):
		leftxor = bin(a[i] ^ b[i])[2:][-1::-1]
		leftxor += '0' * (31 - len(leftxor))
		ans = ''
		a2 = bin(a[i + 1])[2:][-1::-1]
		a2 += '0' * (31 - len(a2))
		for bit in range(len(a2)):
			if leftxor[bit] == '1':
				if a2[bit] == '1':
					ans += '0'
				else:
					ans += '1'
			else:
				ans += '0'
		for bit in range(len(ans)):
			if ans[bit] == '1':
				b[i + 1] += p[bit]
	print(*b)


T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0] * n
	for i in range(1, n):
		ans[i] = (ans[i - 1] ^ a[i - 1]) & ~a[i]
	for i in range(n):
		print(ans[i], end=' ')
	print()


def solution(s):
	res = [0]
	a = s[0]
	i = 1
	while i < len(s):
		a = a | s[i]
		curr = a ^ s[i]
		res.append(curr)
		a = curr ^ s[i]
		i += 1
	return res
n = int(input())
for i in range(n):
	input()
	a = list(map(int, input().split()))
	print(*solution(a))


from collections import Counter as count
from bisect import bisect
import sys
from math import ceil, gcd, log2 as log
from itertools import groupby
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(int(input())):
	n = int(input())
	z = list(map(int, input().split()))
	print(0, end=' ')
	b = z[0]
	for i in z[1:]:
		t = (i ^ b) & b
		print(t, end=' ')
		b = t ^ i
	print()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(a, p) = ([0], l[0])
	for i in range(1, n):
		r = p - (p & l[i])
		p = p | l[i]
		a.append(r)
	print(*a)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from time import time
from itertools import permutations as per
from heapq import heapify, heappush, heappop, heappushpop
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\r\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for i in range(I()):
	n = I()
	a = L()
	ans = [0]
	for i in range(1, n):
		p = a[i - 1] ^ ans[-1]
		ans += (p - (p & a[i]),)
	print(*ans)


def binary(a):
	result = []
	while a:
		result.append(a % 2)
		a //= 2
	result.reverse()
	return result

def change(a, b):
	s1 = binary(a)
	s2 = binary(b)
	ans = []
	if len(s2) < len(s1):
		s2 = [0 for i in range(len(s1) - len(s2))] + s2
	elif len(s1) < len(s2):
		s1 = [0 for i in range(len(s2) - len(s1))] + s1
	f = 0
	for i in range(len(s1)):
		if s1[i] == 1 and s2[i] != 1:
			f = 1
			ans.append(1)
		elif f == 1:
			ans.append(0)
	an = 0
	q = 1
	for i in range(len(ans) - 1, -1, -1):
		an += ans[i] * q
		q *= 10
	san = str(an)
	return int(san, base=2)
t = int(input())
for u in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	ans = [0]
	pr = s[0]
	for i in range(1, n):
		if pr & s[i] == pr:
			ans.append(0)
			pr = s[i]
		else:
			ans.append(change(pr, s[i]))
			pr = ans[-1] ^ s[i]
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	l = x[0]
	for i in range(n):
		print(x[i] ^ l, end=' ')
		if i != n - 1:
			l |= x[i + 1]
	print()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	z = [x[0]]
	y = [0]
	for i in range(1, n):
		if z[i - 1] & x[i] == z[i - 1]:
			z.append(x[i])
			y.append(0)
		else:
			z.append(z[i - 1] | x[i])
			y.append((z[i - 1] | x[i]) ^ x[i])
	print(*y)


import os, sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd
from _collections import deque
import heapq as hp
from bisect import bisect_left, bisect_right
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0]
	for i in range(1, n):
		t = 0
		for j in range(31):
			if a[i - 1] & 1 << j and (not a[i] & 1 << j):
				t += 1 << j
		ans.append(t)
		a[i] ^= t
	print(*ans)


t = int(input())
for i in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	ans = '0 '
	if len(x) > 1:
		x_or = x[0]
		for x_ in x[1:]:
			x_or = x_ | x_or
			x_diff = x_or - x_
			ans += f'{x_diff} '
	print(ans[:-1])


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0]
	for i in range(1, n):
		ans += [(a[i] | a[i - 1]) ^ a[i]]
		a[i] = a[i] | a[i - 1]
	print(*ans)


from sys import stdin
input = stdin.readline

def answer():
	ans = [0]
	for i in range(n - 1):
		x = a[i] - (a[i] & a[i + 1])
		ans.append(x)
		a[i + 1] += x
	return ans
for T in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(*answer())


import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None
		self.BUFSIZE = 8192

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split(' ')))

def get_int_grid(n):
	return [get_ints() for _ in range(n)]

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

def get_strs():
	return get_str().split(' ')

def flat_list(arr):
	return [item for subarr in arr for item in subarr]

def yes_no(b):
	if b:
		return 'YES'
	else:
		return 'NO'

def binary_search(good, left, right, delta=1, right_true=False):
	limits = [left, right]
	while limits[1] - limits[0] > delta:
		if delta == 1:
			mid = sum(limits) // 2
		else:
			mid = sum(limits) / 2
		if good(mid):
			limits[int(right_true)] = mid
		else:
			limits[int(~right_true)] = mid
	if good(limits[int(right_true)]):
		return limits[int(right_true)]
	else:
		return False

def prefix_sums(a):
	p = [0]
	for x in a:
		p.append(p[-1] + x)
	return p

def solve_a():
	_ = get_str()
	a = get_ints()
	b = get_ints()
	f = get_ints()
	z = 0
	if a[0] == b[0] == f[0] and (f[1] - a[1]) * (f[1] - b[1]) < 0:
		z = 2
	elif a[1] == b[1] == f[1] and (f[0] - a[0]) * (f[0] - b[0]) < 0:
		z = 2
	return abs(a[0] - b[0]) + abs(a[1] - b[1]) + z

def solve_b():
	s = get_str()
	n = len(s)
	a = list(string.ascii_lowercase)[:n]
	(i, j) = (0, n - 1)
	while a:
		char = a.pop()
		if s[i] == char:
			i += 1
		elif s[j] == char:
			j -= 1
		else:
			return False
	return True

def solve_c():
	_ = get_str()
	(k, n, m) = get_ints()
	a = get_ints()
	b = get_ints()
	(i, j) = (0, 0)
	r = []
	for _ in range(n + m):
		if i < n and a[i] <= k:
			r.append(a[i])
			if not a[i]:
				k += 1
			i += 1
		elif j < m and b[j] <= k:
			r.append(b[j])
			if not b[j]:
				k += 1
			j += 1
		else:
			return [-1]
	return r

def solve_d():
	n = get_int()
	x = get_ints()
	ans = [0]
	for i in range(1, n):
		tmp = ans[i - 1] ^ x[i - 1]
		new = tmp & ~x[i]
		ans.append(new)
	return ans
t = get_int()
for _ in range(t):
	print(*solve_d())


import math

def solve():
	n = int(input())
	x = list(map(int, input().split()))
	ans = [0]
	for i in range(1, n):
		ans.append((x[i] | x[i - 1] ^ ans[i - 1]) - x[i])
	return ' '.join(map(str, ans))
t = int(input())
while t > 0:
	t -= 1
	print(solve())


def minCo_growingSequenceWith(array):
	(sequence, prevValue) = ('0', array[0])
	for value in array[1:]:
		if prevValue & value != prevValue:
			n = valueToChange(bin(prevValue), bin(value))
			prevValue = value ^ n
			sequence += f' {n}'
		else:
			prevValue = value
			sequence += ' 0'
	return sequence

def valueToChange(binPrev, binCurr):
	(lengthOfPrevValue, lengthOfCurrValue) = (len(binPrev), len(binCurr))
	if lengthOfPrevValue > lengthOfCurrValue:
		binCurr = '0' * (lengthOfPrevValue - 2 - len(binCurr)) + binCurr
	value = ''
	try:
		for x in range(-1, 1 - lengthOfPrevValue, -1):
			if binPrev[x] == '1' != binCurr[x]:
				value = '1' + value
			else:
				value = '0' + value
	except:
		return int(value, 2)
	return int(value, 2)

def testCase_1547d():
	input()
	return tuple(map(int, input().split(' ')))
testCases = (testCase_1547d() for x in range(int(input())))
tuple((print(minCo_growingSequenceWith(testCase)) for testCase in testCases))


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	x = [int(x) for x in input().split()]
	ans = []
	cur = 0
	for i in range(n):
		new = cur & (cur ^ x[i])
		ans.append(new)
		cur = x[i] ^ new
	print(*ans)


from sys import stdin
from bisect import bisect_left, bisect_right, insort_left, insort_right
from math import sqrt, ceil, floor
from collections import Counter, deque
from heapq import heappush, heappop, heapify
input = stdin.readline

def ints():
	return map(int, input().split())
mod = 1000000007

def solve(n, a):
	ans = [0] * n
	for i in range(1, n):
		prev_xor = a[i - 1] ^ ans[i - 1]
		ans[i] = prev_xor & ~a[i]
	return ans
for t in range(int(input())):
	n = int(input())
	a = list(ints())
	print(*solve(n, a))


def foo(a, b):
	(c, d) = (0, 0)
	while b:
		if b & 1:
			c = c | (a & 1 ^ 1) << d
		else:
			c += 0
		d += 1
		a = a >> 1
		b = b >> 1
	return c
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	ans = [0]
	rambo = -1
	for i in range(1, n):
		rambo += 2
		ans.append(foo(x[i], x[i - 1] ^ ans[i - 1]))
	if rambo != 0:
		for i in range(len(ans)):
			print(ans[i], end=' ')
		print()


from math import *
from collections import *
from functools import *
from bisect import *
from itertools import *
from heapq import *
import sys
inf = float('inf')
ninf = -float('inf')
ip = sys.stdin.readline
alphal = 'abcdefghijklmnopqrstuvwxyz'
alphau = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
mod = 10 ** 9 + 7

def ipl():
	return list(map(int, ip().split()))

def ipn():
	return int(ip())

def ipf():
	return float(ip())

def solve():
	n = ipn()
	a = ipl()
	r = [0]
	for i in range(1, n):
		r.append((r[i - 1] ^ a[i - 1] | a[i]) ^ a[i])
	print(*r)
t = ipn()
for _ in range(t):
	solve()


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, 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('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(1, ii() + 1):
		n = ii()
		a = li()
		x = [0]
		x1 = a[0]
		for i in range(1, n):
			p = 0
			for j in range(30):
				if x1 >> j & 1:
					if a[i] >> j & 1:
						pass
					else:
						p |= 1 << j
			x.append(p)
			x1 = p ^ a[i]
		print(*x)
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()


def bnot(n):
	return (1 << n.bit_length()) - 1 - n

def solve(n, x):
	y = []
	for i in range(n):
		if i == 0:
			x[i] = x[i] ^ 0
			y.append(0)
		else:
			xi = x[i - 1] | x[i]
			y.append(x[i] ^ xi)
			x[i] = xi
	return ' '.join(map(str, y))
t = int(input())
for i in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	print(solve(n, x))


def solve(t_id):
	n = int(input())
	x = list(map(int, input().split()))
	y = [0 for i in range(n)]
	for i in range(1, n):
		if x[i] & x[i - 1] != x[i - 1]:
			y[i] = (x[i] | x[i - 1]) ^ x[i]
			x[i] = x[i] ^ y[i]
	print(*y)
t = 1
t = int(input())
for i in range(t):
	solve(i + 1)


import os
import sys
import math
from io import BytesIO, IOBase
import io
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
from collections import Counter
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10001)]
prime[0] = prime[1] = False

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

class DSU:

	def __init__(self, R, C):
		self.par = range(R * C + 1)
		self.rnk = [0] * (R * C + 1)
		self.sz = [1] * (R * C + 1)

	def find(self, x):
		if self.par[x] != x:
			self.par[x] = self.find(self.par[x])
		return self.par[x]

	def union(self, x, y):
		(xr, yr) = (self.find(x), self.find(y))
		if xr == yr:
			return
		if self.rnk[xr] < self.rnk[yr]:
			(xr, yr) = (yr, xr)
		if self.rnk[xr] == self.rnk[yr]:
			self.rnk[xr] += 1
		self.par[yr] = xr
		self.sz[xr] += self.sz[yr]

	def size(self, x):
		return self.sz[self.find(x)]

	def top(self):
		return self.size(len(self.sz) - 1) - 1

class LazySegTree:

	def __init__(self, _op, _e, _mapping, _composition, _id, v):

		def set(p, x):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			_d[p] = x
			for i in range(1, _log + 1):
				_update(p >> i)

		def get(p):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			return _d[p]

		def prod(l, r):
			assert 0 <= l <= r <= _n
			if l == r:
				return _e
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r >> i)
			sml = _e
			smr = _e
			while l < r:
				if l & 1:
					sml = _op(sml, _d[l])
					l += 1
				if r & 1:
					r -= 1
					smr = _op(_d[r], smr)
				l >>= 1
				r >>= 1
			return _op(sml, smr)

		def apply(l, r, f):
			assert 0 <= l <= r <= _n
			if l == r:
				return
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r - 1 >> i)
			l2 = l
			r2 = r
			while l < r:
				if l & 1:
					_all_apply(l, f)
					l += 1
				if r & 1:
					r -= 1
					_all_apply(r, f)
				l >>= 1
				r >>= 1
			l = l2
			r = r2
			for i in range(1, _log + 1):
				if l >> i << i != l:
					_update(l >> i)
				if r >> i << i != r:
					_update(r - 1 >> i)

		def _update(k):
			_d[k] = _op(_d[2 * k], _d[2 * k + 1])

		def _all_apply(k, f):
			_d[k] = _mapping(f, _d[k])
			if k < _size:
				_lz[k] = _composition(f, _lz[k])

		def _push(k):
			_all_apply(2 * k, _lz[k])
			_all_apply(2 * k + 1, _lz[k])
			_lz[k] = _id
		_n = len(v)
		_log = _n.bit_length()
		_size = 1 << _log
		_d = [_e] * (2 * _size)
		_lz = [_id] * _size
		for i in range(_n):
			_d[_size + i] = v[i]
		for i in range(_size - 1, 0, -1):
			_update(i)
		self.set = set
		self.get = get
		self.prod = prod
		self.apply = apply
MIL = 1 << 20

def makeNode(total, count):
	return total * MIL + count

def getTotal(node):
	return math.floor(node / MIL)

def getCount(node):
	return node - getTotal(node) * MIL
nodeIdentity = makeNode(0.0, 0.0)

def nodeOp(node1, node2):
	return node1 + node2
	return makeNode(getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2))
identityMapping = -1

def mapping(tag, node):
	if tag == identityMapping:
		return node
	count = getCount(node)
	return makeNode(tag * count, count)

def composition(mapping1, mapping2):
	return mapping1 if mapping1 != identityMapping else mapping2

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return math.gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = math.gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = math.gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = arr[n - 1]
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] >= key:
			res = arr[mid]
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = -1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][0] >= key:
			right = mid - 1
		else:
			res = mid
			left = mid + 1
	return res
t = 1
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	res = [0]
	for i in range(1, n):
		(last, cur) = (a[i - 1], a[i])
		c = 1
		x = 0
		while last:
			if last % 2 != cur % 2 and last % 2:
				x += c
			c *= 2
			last //= 2
			cur //= 2
		res.append(x)
		a[i] ^= x
	print(*res)


import sys
import math
mod = 10 ** 9 + 7
LI = lambda : [int(k) for k in input().split()]
input = lambda : sys.stdin.readline().rstrip()
IN = lambda : int(input())
S = lambda : input()
r = range
for t in r(IN()):
	n = IN()
	li = LI()
	if n == 1:
		print(0)
		continue
	ans = [0]
	for i in range(1, n):
		ans += [li[i - 1] - (li[i] & li[i - 1])]
		li[i] = ans[-1] ^ li[i]
	print(*ans)


t = int(input())
for i in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	pre = 0
	y = []
	check = []
	for i in range(n):
		y.append(x[i] ^ (pre | x[i]))
		pre = pre | x[i]
	print(*y)


rs = []
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = [0]
	for (i, el) in enumerate(x[1:]):
		prev = y[i] ^ x[i]
		nxt = el & prev
		y.append(prev ^ nxt)
	rs.append(' '.join(map(str, y)))
print(*rs, sep='\n')


for _ in range(int(input().strip())):
	n = int(input().strip())
	x = list(map(int, input().strip().split()))
	y = [0] * n
	t = x[0]
	for i in range(1, n):
		y[i] = (t | x[i]) ^ x[i]
		t = y[i] ^ x[i]
	print(*y)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = [a[0]] + [a[i] | a[i + 1] for i in range(len(a) - 1)]
	r = [0]
	for i in range(1, len(a)):
		c[i] = c[i - 1] | a[i]
		r.append(c[i] - a[i])
	print(*r)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = [0]
	for i in range(1, n):
		if a[i - 1] & a[i] == a[i - 1]:
			ans.append(0)
		else:
			ans.append((a[i] | a[i - 1]) - a[i])
			a[i] = a[i] | a[i - 1]
	print(*ans)


for i in range(0, int(input())):
	input()
	res = 0
	s = []
	for num in input().split():
		x = int(num)
		res = res | x
		s.append(x ^ res)
	print(*s)


for _ in range(int(input())):
	n = int(input())
	y = []
	z = 0
	for x in map(int, input().split()):
		z = ~x & (z ^ x)
		y.append(z)
		z ^= x
	print(*y)


import math

def getList(method=int):
	return list(map(method, input().split()))

def getInt():
	return int(input())

def solve():
	n = getInt()
	arr = getList()
	ans = [0]
	v = arr[0]
	for a in arr[1:]:
		if v & a != v:
			v = (a ^ v) & v
			ans.append(v)
			v = a ^ v
		else:
			ans.append(0)
			v = a
	print(*ans)
for _ in range(getInt()):
	solve()


import sys
import math
import string
import os.path
from collections import *
from queue import *
from bisect import *
from heapq import *
MOD = int(1000000000.0 + 7)
inf = float('inf')
ninf = float('-inf')
input = sys.stdin.buffer.readline

def ii():
	return list(map(int, input().strip().split()))

def deb(a, b='Debugging'):
	print(b, *a) if os.path.exists('inp.txt') else ''
for _ in range(int(input())):
	(n,) = ii()
	x = ii()
	y = [0 for _ in range(n)]
	for i in range(1, n):
		xCur = x[i]
		xPrev = x[i - 1]
		s = 0
		while xPrev > 0:
			bCur = xCur & 1
			bPrev = xPrev & 1
			xCur >>= 1
			xPrev >>= 1
			if bPrev and (not bCur):
				y[i] |= 1 << s
			s += 1
		x[i] ^= y[i]
	print(*y)


import sys
t = int(sys.stdin.readline())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	x = a[0]
	print(0, end=' ')
	for i in range(1, n):
		ans = x & a[i]
		ans = ans ^ x
		print(ans, end=' ')
		x = ans ^ a[i]
	print()
	t -= 1


from collections import Counter, defaultdict, deque
import math
import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	arr = [int(_) for _ in input().split()]
	cur = arr[0]
	ans = [0]
	for i in range(1, n):
		a = arr[i]
		cur |= arr[i]
		ans.append(~a & cur)
	print(*ans)
tt = int(input())
for test in range(tt):
	solve()


import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import collections
import itertools
import bisect
import heapq
import random

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def primeFactorsCount(n):
	cnt = 0
	while n % 2 == 0:
		cnt += 1
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			cnt += 1
			n = n // i
	if n > 2:
		cnt += 1
	return cnt

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	i = 2
	while i * i <= n:
		if primes[i] == True:
			for j in range(i * i, n + 1, i):
				primes[j] = False
		i += 1
	pr = []
	for i in range(0, n + 1):
		if primes[i]:
			pr.append(i)
	return pr

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac

def sod(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s

def getNum(a, b):
	a = binary(a)
	b = binary(b)
	if len(a) > len(b):
		b = '0' * (len(a) - len(b)) + b
	a = a[::-1]
	b = b[::-1]
	ans = []
	for i in range(0, len(a)):
		if a[i] == '1' and b[i] == '0':
			ans.append('1')
		else:
			ans.append('0')
	ans = ''.join(ans)
	ans = ans[::-1]
	return ans
for xyz in range(0, int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = [0]
	for i in range(1, n):
		prev = ans[-1] ^ l[i - 1]
		temp = getNum(prev, l[i])
		ans.append(decimal(temp))
	print(*ans)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	ans = ['0']
	for i in range(n - 1):
		if a[i] & a[i + 1] == a[i]:
			ans.append('0')
		else:
			temp = (a[i] ^ a[i + 1]) & a[i]
			a[i + 1] = a[i + 1] ^ temp
			ans.append(str(temp))
	print(' '.join(ans))


try:
	import sys

	def solve():
		n = int(input())
		x = list(map(int, input().split()))
		result = 0
		for i in x:
			result = result | i
			sys.stdout.write(str(result ^ i) + ' ')
		sys.stdout.write('\n')
	test = int(input())
	count1 = 1
	while count1 <= test:
		solve()
		count1 += 1
except EOFError:
	print('')


def func():
	lst = [0]
	for i in range(1, n):
		ele = (lst[-1] ^ x[i - 1] | x[i]) ^ x[i]
		lst.append(ele)
	print(*lst)
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	func()


def minm(x):
	s = list(bin(x)[2:][::-1])
	if not '0' in s:
		s += '1'
	else:
		s[s.index('0')] = '1'
	return int(''.join(s)[::-1], 2)

def f(a, b):
	y = 0
	for i in range(32):
		if b // 2 ** i % 2 == 1 and a // 2 ** i % 2 != 1:
			y += 2 ** i
	return y

def solve(n, x):
	y = [0] * n
	z = [0] * n
	z[0] = x[0] ^ y[0]
	for i in range(1, n):
		y[i] = f(x[i], z[i - 1])
		z[i] = x[i] ^ y[i]
	print(*y)
(t,) = map(int, input().split())
for _ in range(t):
	(n,) = map(int, input().split())
	(*a,) = map(int, input().split())
	solve(n, a)


def fun(x, y):
	return x & ~y
t = int(input())
for i in range(t):
	n = int(input())
	z = list(map(int, input().split()))
	ans = [0] * n
	for i in range(1, n):
		ans[i] = fun(z[i - 1] ^ ans[i - 1], z[i])
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if n == 1:
		print('0')
		continue
	ans = []
	for i in range(len(arr)):
		if i == 0:
			ans.append(0)
			continue
		else:
			ans.append((arr[i] | ans[i - 1] ^ arr[i - 1]) - arr[i])
	print(' '.join([str(i) for i in ans]))


def solve():
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [0] * n
	for i in range(1, n):
		d = [i for i in bin(a[i])[2:]]
		c = [i for i in bin(a[i - 1])[2:]]
		p = len(c)
		if p < len(d):
			d = d[-p:]
		if p > len(d):
			d = ['0'] * (p - len(d)) + d
		res = [0] * p
		for j in range(p):
			if c[j] == '1' and c[j] != d[j]:
				res[j] = 1
		b[i] = int(''.join((str(elem) for elem in res)), 2)
		a[i] = a[i] ^ b[i]
	print(' '.join((str(elem) for elem in b)))
	return
for t in range(int(input())):
	solve()


T = int(input())
for tc in range(1, T + 1):
	N = int(input())
	numbers = list(map(int, input().split()))
	prefix = '0b'
	answer = [0]
	if len(numbers) == 1:
		print(*answer)
	else:
		for i in range(1, len(numbers)):
			before = numbers[i - 1] ^ answer[i - 1]
			answer.append(before & ~numbers[i])
		print(*answer)


from itertools import combinations_with_replacement
import sys
from sys import stdin
import math
import bisect

def BinarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def iinput():
	return int(input())

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

def linput():
	return list(map(int, input().split()))

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

def fminput():
	return map(int, stdin.readline().strip().split())

def flinput():
	return list(map(int, stdin.readline().strip().split()))
for _ in range(iinput()):
	n = iinput()
	list1 = linput()
	list2 = [0]
	for i in range(1, n):
		prev = bin(list1[i - 1])
		nex = bin(list1[i])
		l1 = len(prev)
		l2 = len(nex)
		if l2 < l1:
			nex = nex[0:2] + '0' * (l1 - l2) + nex[2:]
		if l1 < l2:
			prev = prev[0:2] + '0' * (l2 - l1) + prev[2:]
		y = '0b'
		for j in range(2, len(prev)):
			if prev[j] == '0':
				y = y + '0'
			elif prev[j] == '1' and nex[j] == '1':
				y = y + '0'
			elif prev[j] == '1' and nex[j] == '0':
				y = y + '1'
		list1[i] = list1[i] ^ int(y, 2)
		list2.append(int(y, 2))
	print(*list2)


for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	ans = [0]
	ors = [array[0]]
	for i in range(1, len(array)):
		ors.append(ors[-1] | array[i])
		ans.append(ors[i] ^ array[i])
	print(*ans)


import sys
from math import log, floor

def main():
	inp = [int(x) for x in sys.stdin.read().split()]
	ii = 0
	t = inp[ii]
	ii += 1
	for _ in range(t):
		n = inp[ii]
		ii += 1
		ar = inp[ii:ii + n]
		ii += n
		dream = [ar[0]]
		top = []
		for o in range(n - 1):
			dream.append(dream[-1] ^ ar[o + 1] | dream[-1])
		for i in range(n):
			top.append(dream[i] ^ ar[i])
		print(' '.join(list(map(str, top))))
main()


T = int(input())
for t in range(T):
	n = int(input())
	x = list(map(int, input().split()))
	y = []
	y.append(0)
	for i in range(n - 1):
		b = x[i] | x[i + 1]
		y.append(abs(x[i + 1] - b))
		x[i + 1] = b
	print(*y)


t = int(input())
for _ in range(t):
	n = int(input())
	bunch = list(map(int, input().split()))
	res = 0
	for i in range(n):
		y = res & ~bunch[i]
		res = bunch[i] ^ y
		print(y, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	ans = [0]
	l1 = list(map(int, input().split()))
	for i in range(1, n):
		ans.append(~(~(ans[-1] ^ l1[i - 1]) | l1[i]))
	print(' '.join(map(str, ans)))


from collections import defaultdict as df
import sys
input = lambda : sys.stdin.readline().rstrip()

def compare(a, b):
	n1 = len(a) - 1
	n2 = len(b) - 1
	more = False
	ans = []
	while True:
		if n2 <= 1 and n1 <= 1:
			break
		if n2 <= 1:
			ans.append(a[n1])
			n1 -= 1
		elif n1 <= 1:
			more = True
			ans.append('0')
			n2 -= 1
		else:
			if a[n1] == b[n2]:
				ans.append('0')
			elif a[n1] == '1' and b[n2] == '0':
				ans.append('1')
			else:
				more = True
				ans.append('0')
			n1 -= 1
			n2 -= 1
	return (ans, more)
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [0]
	ini = bin(arr[0])
	for i in range(1, n):
		cmp = bin(arr[i])
		(res, more) = compare(ini, cmp)
		res.reverse()
		res = int(''.join(res), 2)
		ini = bin(res ^ arr[i])
		ans.append(res)
	print(*ans)


from typing import Counter
import sys
from collections import defaultdict as dd
from math import *

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

def linp():
	return list(map(int, input().split()))

def sinp():
	return input()

def inp():
	return int(input())

def mod(f):
	return f % 1000000007

def pr(*x):
	print(*x)

def finp():
	f = open('input.txt', 'r')
	f = f.read().split('\n')
	return f

def finp():
	f = open('input.txt', 'r')
	f = f.read().split('\n')
	return f

def fout():
	return open('output.txt', 'w')

def fpr(f, x):
	f.write(x + '\n')

def csort(c):
	sorted(c.items(), key=lambda pair: pair[1], reverse=True)

def indc(l, n):
	c = {}
	for i in range(n):
		c[l[i]] = c.get(l[i], []) + [i + 1]
	return c
cou = inp()
for i in range(cou):
	(a, b, f) = (inp(), linp(), [])
	c = b[0]
	print(0, end=' ')
	for i in range(1, a):
		temp = c & b[i] ^ c
		print(temp, end=' ')
		c = temp ^ b[i]
	pr()


from math import ceil, log2

def f(n):
	rs = []
	while n:
		rs.append(n % 2)
		n //= 2
	return rs[::-1]
for _ in range(int(input())):
	n = int(input())
	s = [int(x) for x in input().split()]
	res = [0]
	for i in range(1, n):
		q = f(s[i])
		w = f(s[i - 1])
		if len(q) < len(w):
			q = [0] * (len(w) - len(q)) + q
		rs = 0
		k = 0
		for j in range(-1, -len(w) - 1, -1):
			if w[j] and q[j] == 0:
				rs += 2 ** k
			k += 1
		s[i] = s[i] ^ rs
		res.append(rs)
	print(*res)


from sys import stdin, stdout, setrecursionlimit
from io import BytesIO, IOBase
setrecursionlimit(10000)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None
		self.BUFSIZE = 8192

	def read(self):
		while True:
			a = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			if not a:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(a), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			a = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			self.newlines = a.count(b'\n') + (not a)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(a), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
input = lambda : stdin.readline().rstrip('\r\n')
inp = lambda : int(input())
st = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
int_arr = lambda : list(map(int, input().strip().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().strip().split())
get_int = lambda : map(int, input().strip().split())
get_float = lambda : map(float, input().strip().split())
mod = 1000000007
for _ in range(inp()):
	n = inp()
	arr = int_arr()
	print(0, end=' ')
	for i in range(1, n):
		ans = arr[i] | arr[i - 1]
		ans = ans ^ arr[i]
		arr[i] = ans ^ arr[i]
		print(ans, end=' ')
	print()


import math
import sys
inp = int(input())
for _ in range(inp):
	n = int(input())
	x = list(map(int, input().split(' ')))
	res = [0]
	for i in range(1, n):
		t = x[i - 1] ^ res[i - 1]
		s = t ^ x[i]
		s = s & t
		res.append(s)
	print(' '.join(map(str, res)))


t = int(input())
for j in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	ans = [0]
	for i in range(1, n):
		k = 0
		otv = 0
		while 2 ** k <= max(x[i], x[i - 1]):
			if 2 ** k & x[i - 1] == 2 ** k and 2 ** k & x[i] == 0:
				otv += 2 ** k
				x[i] = x[i] ^ 2 ** k
			k += 1
		ans.append(otv)
	print(*ans)


from sys import *
from bisect import *
from math import *
from collections import *
from heapq import *
from itertools import *
inf = 10 ** 18
mod = 10 ** 9 + 7

def check(a, b):
	while a > 0:
		if a & 1 and b & 1 == 0:
			return False
		a >>= 1
		b >>= 1
	return True

def change(a, b):
	temp = 0
	cnt = 0
	while a:
		if a & 1 and b & 1 == 0:
			temp += 2 ** cnt
		a >>= 1
		b >>= 1
		cnt += 1
	return temp
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	ans = [0]
	temp = x[0] ^ 0
	for i in range(1, n):
		if check(temp, x[i]):
			ans.append(0)
			temp = 0 ^ x[i]
		else:
			newXor = change(temp, x[i])
			temp = newXor ^ x[i]
			ans.append(newXor)
	print(*ans)


import fileinput

def main():
	it = fileinput.input()
	num_cases = int(next(it))
	for _ in range(num_cases):
		next(it)
		a = list(map(int, next(it).split()))
		f(a)

def f(a):
	i = 1
	cosequence = [0]
	a_len = len(a)
	while i < a_len:
		a1 = a[i - 1]
		a2 = a[i]
		y1 = cosequence[i - 1]
		t1 = a1 | y1
		y2 = (a2 | t1) - a2
		cosequence.append(y2)
		i += 1
	print(' '.join(map(str, cosequence)))
main()


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	ans = [0]
	for i in range(1, n):
		need = (x[i - 1] | x[i]) ^ x[i]
		ans.append(need)
		x[i] = x[i] ^ need
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	pst = [0]
	k = lst[0]
	for x in lst[1:]:
		m = (k ^ x) & k
		pst.append(m)
		k = m ^ x
	print(*pst)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = [0]
	for i in range(1, n):
		z = arr[i - 1] & arr[i]
		y = arr[i - 1] - z
		if y == 0:
			ans.append(0)
		else:
			ans.append(arr[i] ^ arr[i] + y)
			arr[i] = arr[i] + (arr[i - 1] - z)
	print(*ans)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	data = list(map(int, input().split()))
	answer = [0]
	for i in range(1, n):
		prev = data[i - 1] ^ answer[i - 1]
		next = prev | data[i]
		answer.append(next ^ data[i])
	print(' '.join(map(str, answer)))


from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations, accumulate
from math import gcd, floor, inf, log2, sqrt, log10
from bisect import bisect_right, bisect_left
from statistics import mode
power_of_two = lambda number: int(log2(number))
cases = int(input())
for _ in range(cases):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [0]
	prev = arr[0] | 0
	for num in arr[1:]:
		temp = (prev | num) ^ num
		ans.append(temp)
		prev = prev | num
	print(*ans)


def sol():
	n = int(input())
	a = [int(i) for i in input().split()]
	res = [0]
	for i in range(1, n):
		res += [(a[i] | a[i - 1] | res[i - 1]) - a[i]]
	return res
for _ in range(int(input())):
	print(*sol(), sep=' ')


t = int(input())
for _ in range(t):
	n = int(input())
	X = list(map(int, input().split()))
	Y = [0]
	for (x1, x2) in zip(X, X[1:]):
		y = Y[-1]
		t = x1 ^ y
		ny = 0
		for i in range(31):
			if t & 1 << i and (not x2 & 1 << i):
				ny += 1 << i
		assert (x1 ^ y) & (x2 ^ ny) == x1 ^ y
		Y.append(ny)
	print(' '.join((str(i) for i in Y)))


from sys import *
from collections import defaultdict as dd
from math import *
from bisect import *

def sinp():
	return input()

def inp():
	return int(sinp())

def minp():
	return map(int, sinp().split())

def linp():
	return list(minp())

def strl():
	return list(sinp())

def pr(x):
	print(x)
mod = int(1000000000.0 + 7)
for _ in range(inp()):
	n = inp()
	x = linp()
	ans = []
	p = x[0]
	for i in range(1, n):
		ans.append(p & x[i] ^ p)
		p = p & x[i] ^ p ^ x[i]
	print(0, *ans)


t = int(input())
for i in range(t):
	n = input()
	res = 0
	sp = map(int, input().split())
	for j in sp:
		res |= j
		print(j ^ res, end=' ')
	print()


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import Decimal
from decimal import *
from collections import defaultdict, deque
import heapq
from decimal import Decimal
getcontext().prec = 25
abcd = 'abcdefghijklmnopqrstuvwxyz'
MOD = pow(10, 9) + 7
BUFSIZE = 8192
from bisect import bisect_left, bisect_right

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split(' ')))
	ans = []
	v = [0] * 30
	for i in range(n):
		x = bin(l[i])[2:]
		x = x[::-1] + '0' * (30 - len(x))
		j = 0
		val = 0
		for k in x:
			if int(k) == 0 and v[29 - j] == 1:
				val += 2 ** j
			if int(k) == 1:
				v[29 - j] = 1
			j += 1
		ans.append(val)
	print(*ans)


def f(x, y):
	return x & ~y
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = [0 for i in range(n)]
	for i in range(1, n):
		b[i] = f(b[i - 1] ^ a[i - 1], a[i])
	for x in b:
		print(x, end=' ')
	print()


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections, string, bisect, re, random, queue, itertools, statistics, math
from collections import *
from bisect import *
from string import *
from itertools import *
from statistics import *
from math import *
from re import *
from queue import *

class Stack:

	def __init__(self):
		self.items = []

	def push(self, item):
		self.items.append(item)

	def pop(self):
		return self.items.pop()

	def empty(self):
		return self.items == []

	def size(self):
		return len(self.items)

	def at(self, idx):
		try:
			return self.items[idx]
		except:
			return -1

class priority_queue(object):

	def __init__(self):
		self.queue = []

	def __str__(self):
		return ' '.join([str(i) for i in self.queue])

	def empty(self):
		return len(self.queue) == 0

	def push(self, data):
		self.queue.append(data)

	def pop(self):
		try:
			max = 0
			for i in range(len(self.queue)):
				if self.queue[i] > self.queue[max]:
					max = i
			item = self.queue[max]
			del self.queue[max]
			return item
		except IndexError:
			print()
			exit()
mod = int(1000000000.0 + 7)
imax = float('inf')
imin = float('-inf')
true = True
false = False
N = int(100000.0)
none = None
inp = lambda : input()
I = lambda : int(inp())
M = lambda : map(int, inp().split())
MS = lambda : map(str, inp().split())
S = lambda : list(MS())
L = lambda : list(M())

def IO():
	try:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('uttar.txt', 'w')
	except:
		pass
IO()

class helper:

	def first(self, arr):
		return arr[0]

	def second(self, arr):
		return arr[1]

	def is_sorted(self, arr):
		return arr == sorted(arr)

def kabraji_ka_totka():
	n = I()
	arr = L()
	temp = 0
	for i in arr:
		temp |= i
		print(temp ^ i)
case = 1
case = I()
for i in range(case):
	kabraji_ka_totka()


import sys
ref = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648]

def process(t, nums):
	if t == 1:
		return [0]
	else:
		toreturn = [0]
		for i in range(1, t):
			a = nums[i - 1]
			b = nums[i]
			r = a & b
			toreturn.append(a - r)
			nums[i] += a - r
	return toreturn
t = int(input())
for i in range(t):
	n = int(input())
	nums = [int(x) for x in input().split()]
	save = process(n, nums)
	sys.stdout.write(' '.join(map(str, save)) + '\n')


for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = [0]
	z = x[0] ^ 0
	for i in range(1, n):
		a = 0
		for j in range(30):
			if z // 2 ** j % 2:
				a += (1 - x[i] // 2 ** j % 2) * 2 ** j
		y.append(a)
		z = x[i] ^ a
	print(*y)


t = int(input())
lim = pow(2, 30)
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [0]
	for i in range(1, n):
		c = 1
		temp = 0
		while c < lim:
			if arr[i - 1] & c:
				if arr[i] & c == 0:
					arr[i] += c
					temp += c
			c *= 2
		ans.append(temp)
	for i in ans:
		print(i, end=' ')
	print()


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	tmp = input().split()
	x = []
	y = []
	y.append(0)
	for i in tmp:
		x.append(int(i))
	for i in range(1, n):
		y.append(~x[i] & x[i - 1])
		x[i] = x[i] ^ y[i]
	for i in y:
		print(i, end=' ')
	print()


def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		ans = [0]
		for i in range(1, n):
			if a[i - 1] & a[i] == a[i - 1]:
				ans.append(0)
			else:
				b1 = bin(a[i - 1])[2:][::-1]
				n1 = len(b1)
				temp = 0
				for j in range(n1):
					if b1[j] == '1':
						if not a[i] & 1 << j:
							temp += 2 ** j
				ans.append(temp)
				a[i] = a[i] ^ temp
		print(*ans)
main()


def f(x, y):
	return (x | y) ^ y
t = int(input())
while t > 0:
	n = int(input())
	nums = list(map(int, input().split()))
	ans = [0]
	for i in range(1, n):
		ans.append(f(nums[i - 1] ^ ans[i - 1], nums[i]))
	print(' '.join(map(str, ans)))
	t -= 1


from sys import stdin

def get_ints():
	return list(map(int, stdin.readline().strip().split()))
for _ in range(int(input())):
	n = int(input())
	ar = get_ints()
	res = [0] * n
	for i in range(1, n):
		prev = ar[i - 1] ^ res[i - 1]
		curr = ar[i]
		new = prev & ~ar[i]
		res[i] = new
	print(' '.join([str(x) for x in res]))


def ans(a, n):
	arr = [0]
	for i in range(1, n):
		x_prev = a[i - 1] + arr[i - 1]
		x_curr = a[i]
		z = x_curr & x_prev
		arr.append(x_prev - z)
	return arr
n = int(input())
for i in range(n):
	m = int(input())
	b = input().split()
	a = []
	for i in b:
		a.append(int(i))
	x = ans(a, m)
	for i in x:
		print(i, end=' ')
	print()


def f(x, y):
	return x & ~y
_ = int(input())
for tt in range(_):
	n = int(input())
	t = list(map(int, input().split()))
	w = [0] * n
	for i in range(1, n):
		w[i] = f(w[i - 1] ^ t[i - 1], t[i])
	print(' '.join(map(str, w)))


def fun(a, b):
	return a & ~b
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = [0] * n
	for i in range(1, n):
		y[i] = fun(y[i - 1] ^ x[i - 1], x[i])
	print(' '.join(map(str, y)))


n = int(input())
for k in range(n):
	nn = input()
	a = list(map(int, input().split()))
	ans = [0]
	for i in range(1, len(a)):
		st = 1
		an = 0
		while st <= a[i - 1]:
			if a[i - 1] // st % 2 - a[i] // st % 2 == 1:
				an += st
				a[i] += st
			st *= 2
		ans.append(an)
	print(*ans, sep=' ')


for _ in range(int(input())):
	n = int(input())
	arrX = list(map(int, input().split()))
	arrY = [0]
	for i in range(1, n):
		arrY.append((arrX[i - 1] ^ arrY[i - 1] | arrX[i]) ^ arrX[i])
	print(' '.join(map(str, arrY)))


def ne_0(a, b):
	c = 1
	while c <= a:
		if c & a == c:
			b = b | c
		c = c << 1
	return b
t = int(input())
for aaaaaaaaa in range(t):
	n = int(input())
	x = [int(i) for i in input().split()]
	y = [0]
	t = [x[0]]
	print(0, end=' ')
	for i in range(1, n):
		t.append(ne_0(t[i - 1], x[i]))
		y.append(t[i] - x[i])
		print(y[i], end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * n
	for i in range(n - 1):
		if a[i] & a[i + 1] == a[i]:
			b[i + 1] = 0
		else:
			j = 0
			ta = 0
			for k in range(30):
				if a[i] & 1 << j != 0 and a[i + 1] & 1 << j == 0:
					ta += 1 << j
				j += 1
			b[i + 1] = ta
		a[i + 1] = a[i + 1] ^ b[i + 1]
	for i in range(n):
		print(b[i], end=' ')
	print()


t = int(input())
for _ in range(t):
	input()
	x = list(map(int, input().split()))
	z = [0]
	for i in range(1, len(x)):
		temp = x[i - 1] ^ z[i - 1]
		temp = temp | x[i]
		temp = temp ^ x[i]
		z.append(temp)
	print(' '.join(map(str, z)))


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import deque
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	o = [a[0]]
	for i in a[1:]:
		o.append(o[-1] | i)
	ans = []
	for i in range(n):
		ans.append(a[i] ^ o[i])
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	ans = 0
	for v in x:
		req = (ans | v) - v
		print(req, end=' ')
		ans |= v
	print()


from sys import stdout
out = lambda x, end='\n': stdout.write(str(x) + end)
for s in [*open(0)][2::2]:
	a = list(map(int, s.split()))
	b = [0]
	for i in range(1, len(a)):
		and_ = a[i] & a[i - 1]
		xor_ = and_ ^ a[i - 1]
		b.append(xor_)
		a[i] ^= xor_
	print(*b)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
import math
from bisect import *
from heapq import *
from collections import defaultdict as dd
from collections import OrderedDict as odict
from collections import Counter as cc
from collections import deque
from itertools import groupby
sys.setrecursionlimit(20 * 20 * 20 * 20 + 10)

def solve():
	n = takein()
	arr = takeiar()
	growing = True
	for i in range(1, n):
		if arr[i] & arr[i - 1] != arr[i - 1]:
			growing = False
			break
	if growing:
		for i in range(n):
			print(0, end=' ')
		return
	else:
		print(0, end=' ')
		for i in range(1, n):
			temp = arr[i - 1] ^ arr[i]
			temp = temp & arr[i - 1]
			arr[i] ^= temp
			print(temp, end=' ')
	print()

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = takein()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

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

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

def takeiar():
	return list(map(int, sys.stdin.readline().rstrip('\r\n').split()))

def takesar():
	return list(map(str, sys.stdin.readline().rstrip('\r\n').split()))

def takeivr():
	return map(int, sys.stdin.readline().rstrip('\r\n').split())

def takesvr():
	return map(str, sys.stdin.readline().rstrip('\r\n').split())

def ispalindrome(s):
	return s == s[::-1]

def invert(bit_s):
	temp = int(bit_s, 2)
	inverse_s = temp ^ 2 ** (len(bit_s) + 1) - 1
	rslt = bin(inverse_s)[3:]
	return str(rslt)

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

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

def ceil(a, b):
	return -(-a // b)

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

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


import sys
input = sys.stdin.readline
for t in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	zeros = [a[0] & 1 << i for i in range(30)]
	b = [0] * n
	for idx in range(1, n):
		i = a[idx]
		num = 0
		for j in range(30):
			if zeros[j]:
				if not i & 1 << j:
					num += 1 << j
			elif i & 1 << j:
				zeros[j] = 1 << j
		b[idx] = num
	print(*b)


from math import ceil, floor, log2

def invert(a, m):
	if m == 0:
		return 0
	k = 2 ** (floor(log2(m)) + 1) - 1
	return a ^ k
for t in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = [0] * n
	cur = x[0]
	m = max(x)
	for i in range(0, n - 1):
		y[i + 1] = cur & invert(x[i + 1], m)
		cur = x[i + 1] ^ y[i + 1]
	print(*y)


import math
from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, gcd, log2
import bisect
import sys
import random
import heapq
from sys import stdout

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def getPosOfRightmostSetBit(n):
	return floor(log2((n & -n) + 1))

def getPosOfRightMostUnsetBit(n):
	if n == 0:
		return 1
	if n & n + 1 == 0:
		return -1
	return getPosOfRightmostSetBit(~n)
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	prev_val = a[0]
	arr = [0]
	for i in range(1, n):
		to_inc = (a[i] | prev_val) - a[i]
		arr.append(to_inc)
		prev_val = a[i] ^ arr[-1]
	print(*arr)


import os, sys, math
from io import BytesIO, IOBase
from collections import defaultdict, deque, OrderedDict
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

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

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

def ln():
	return list(map(int, input().split()))

def Sn():
	return input().strip()
BUFSIZE = 8192

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def solve():
	n = I()
	l = list(In())
	mx = l[0]
	ans = [0]
	for i1 in range(1, n):
		(z1, z2) = (bin(mx), bin(l[i1]))
		(z1, z2) = (list(z1[2:]), list(z2[2:]))
		mx = max(len(z1), len(z2))
		an = ['0'] * mx
		for i in range(mx - len(z1)):
			z1.insert(0, '0')
		for i in range(mx - len(z2)):
			z2.insert(0, '0')
		for i in range(len(z1) - 1, -1, -1):
			if z1[i] == '1':
				if z2[i] == '0':
					an[i] = '1'
				else:
					continue
		ans.append(int(''.join(an), 2))
		mx = l[i1] | ans[-1]
	print(*ans)
	pass

def main():
	T = I()
	for i in range(T):
		solve()
M = 998244353
P = 1000000007

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from math import *
import sys
import collections
from random import *
sys.setrecursionlimit(99999)
eps = sys.float_info.epsilon

def is_prime(n):
	d = 2
	while d * d <= n:
		if n % d == 0:
			return False
		d += 1
	return True

def solve():
	try:
		n = int(input())
		x = list(map(int, input().split()))
		ans = [0]
		for i in range(1, n):
			prev = x[i - 1]
			now = x[i]
			j = 1
			res = 0
			xor_prev = prev ^ ans[i - 1]
			if xor_prev != 0:
				while j <= floor(log2(xor_prev)) + 1:
					if xor_prev >> j - 1 & 1 == 1 and now >> j - 1 & 1 == 0:
						res += 2 ** (j - 1)
					j += 1
				ans.append(res)
			else:
				ans.append(0)
		print(*ans)
	except Exception as e:
		print(e)
for _ in range(int(input())):
	solve()


def sol():
	n = int(input())
	arr = [int(x) for x in input().split()]
	tab = [0]
	for i in range(1, n):
		pom = 0
		for j in range(32):
			if 1 << j & arr[i - 1] and (not 1 << j & arr[i]):
				pom ^= 1 << j
		tab.append(pom)
		arr[i] ^= tab[i]
	print(*tab)

def main():
	for i in range(int(input())):
		sol()
main()


from collections import defaultdict
import sys, io, os
INP = sys.stdin.readline
inp = lambda : [*map(int, INP().encode().split())]
sinp = lambda : [*map(str, INP().split())]
out = sys.stdout.write

def main():
	for _ in range(inp()[0]):
		n = inp()[0]
		d = defaultdict(int)
		l = inp()
		y = [0]
		ans = [l[0]]
		for i in range(1, n):
			y.append(ans[i - 1] & l[i] ^ ans[i - 1])
			ans.append(y[i] ^ l[i])
		print(*y)

def SumOfExpOfFactors(a):
	fac = 0
	lis = SortedList()
	if not a & 1:
		lis.add(2)
	while not a & 1:
		a >>= 1
		fac += 1
	for i in range(3, int(a ** 0.5) + 1, 2):
		if not a % i:
			lis.add(i)
		while not a % i:
			a //= i
			fac += 1
	if a != 1:
		lis.add(a)
		fac += 1
	return (fac, lis)
div = [0] * 1000001

def NumOfDivisors(n):
	for i in range(1, n + 1):
		for j in range(i, n + 1, i):
			div[j] += 1

def primes1(n):
	sieve = [True] * (n // 2)
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i // 2]:
			sieve[i * i // 2::i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [2 * i + 1 for i in range(1, n // 2) if sieve[i]]

def GCD(a, b):
	if b == 0:
		return a
	else:
		return GCD(b, a % b)

class Graph:

	def __init__(self):
		self.Graph = defaultdict(list)

	def addEdge(self, u, v):
		self.Graph[u].append(v)
		self.Graph[v].append(u)

	def DFSUtil(self, v, visited):
		visited.add(v)
		for neighbour in self.Graph[v]:
			if neighbour not in visited:
				self.DFSUtil(neighbour, visited)

	def DFS(self, v):
		visited = set()
		self.DFSUtil(v, visited)

	def BFS(self, s):
		visited = set()
		queue = []
		queue.append(s)
		visited.add(s)
		while queue:
			s = queue.pop(0)
			for i in self.Graph[s]:
				if i not in visited:
					queue.append(i)
					visited.add(i)

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
main()


import sys

def main():
	t = Iint()
	for _ in range(t):
		n = Iint()
		a = Ilist()
		b = [0] * n
		for i in range(n):
			b[i] = a[i] | b[i - 1]
		b[0] = 0
		for i in range(1, n):
			b[i] = b[i] ^ a[i]
		Plist(b)
FIO = 10

def debug(*args, c=6):
	starter = '\x1b[3{}m'.format(c)
	ender = '\x1b[0m'
	if c == 0:
		(starter, ender) = ('', '')
	print(starter, *args, ender, file=sys.stderr, sep=' ')
BUFSIZE = 8 * 1024
en = enumerate
inf = float('inf')

def Istr():
	return input()

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

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

def Plist(li, s=' '):
	print(s.join(map(str, li)))
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
else:
	from io import BytesIO, IOBase
	import os

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

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


from functools import reduce
import os
import sys
from collections import *
from decimal import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]

def Ceil(a, b):
	return a // b + int(a % b > 0)
alphabet = 'abcdefghijklmnopqrstuvwxyz'
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	n = inn()
	a = arr()
	ans = [0]
	for i in range(n - 1):
		if a[i] & a[i + 1] == a[i]:
			ans.append(0)
		else:
			val1 = a[i]
			val2 = a[i + 1]
			res = ''
			new = ''
			while val1:
				if val1 & 1 == 1 and val2 & 1 == 0:
					res = '1' + res
					new = '1' + new
				else:
					res = '0' + res
					new = str(val2 & 1) + new
				val1 = val1 >> 1
				val2 = val2 >> 1
			while val2:
				new = str(val2 & 1) + new
				val2 = val2 >> 1
			ans.append(int(res, 2))
			a[i + 1] = int(new, 2)
	print(*ans)