You are playing a game of Nim with a friend. The rules are are follows:

1) Initially, there are N piles of stones. Two players play alternately.

2) In each turn, a player can choose one non empty pile and remove any number of stones from it. At least one stone must be removed.

3) The player who picks the last stone from the last non empty pile wins the game.

It is currently your friend's turn. You suddenly realize that if your friend was to play optimally in that position, you would lose the game. So while he is not looking, you decide to cheat and add some (possibly 0) stones to each pile. You want the resultant position to be such that your friend has no guaranteed winning strategy, even if plays optimally. You cannot create a new pile of stones. You can only add stones, and not remove stones from a pile. What is the least number of stones you need to add?

Input Format

The first line contains the number of cases T. T cases follow. Each case contains the number N on the first line followed by N numbers on the second line. The ith number denotes si, the number of stones in the ith pile currently.

Constraints

1 <= T <= 20

2 <= N <= 15

1 <= si < 1000000000 ($10^9$)

Output Format

Output T lines, containing the answer for each case. If the current position is already losing for your friend, output 0.

Sample Input

3

2

1 3

3

1 1 1

4

10 4 5 1

Sample Output

2

3

6

Explanation

For the first case, add 2 stones to the first pile. Then, both piles will have 3 stones each. It is easy to verify that your friend cannot win the game unless you make a mistake.

For the second case, add 1 stone to the first pile, and 2 stones to the second pile.

Source: hackerrank | Difficulty: HARD
Tags: Dynamic programming


Solutions:
import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import functools
import itertools
import operator
import os

def find_bit0(n, start_bit=0):
	for bit in itertools.count(start_bit):
		if n & 1 << bit == 0:
			return bit

def unfairGame(s):
	ss = list(s)
	while True:
		v = functools.reduce(operator.xor, ss, 0)
		if v == 0:
			break
		bitlen = v.bit_length()
		i = -1
		while True:
			ll = [(find_bit0(n, bitlen - 1), n, ii) for (ii, n) in enumerate(ss) if ii != i]
			(nbit, n, i) = max(ll, key=lambda t: (-t[0], t[1] & (1 << t[0]) - 1, t[2]))
			if nbit == bitlen - 1:
				break
			bitlen = nbit + 1
		m1 = 1 << nbit
		mask = m1 - 1
		ss[i] = (ss[i] ^ m1) & ~mask
	return sum(ss) - sum(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import math
import os
import random
import re
import sys

def unfairGame(s):
	numsum = 0
	for i in s:
		numsum ^= int(i)
	if numsum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(numsum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
	s_count = int(input().strip())
	s = list(map(int, input().rstrip().split()))
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import math
import os
import random
import re
import sys
import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import math
import os
import random
import re
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
	s_count = int(input().strip())
	s = list(map(int, input().rstrip().split()))
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import os
import sys

def mmmm(o):
	kmm = 0
	for i in o:
		kmm ^= int(i)
	if kmm == 0:
		return 0
	print(o)
	divideris = 2 ** (len(bin(kmm)) - 3)
	print(divideris)
	modlist = [x % divideris if x % (2 * divideris) < divideris else -1 for x in o]
	print(modlist)
	if max(modlist) < 0:
		o[o.index(max(o))] += divideris
		return divideris + mmmm(o)
	innn = max(modlist)
	increase = divideris - innn
	print(increase)
	o[modlist.index(innn)] += increase
	print(o)
	print()
	return increase + mmmm(o)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
p = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for p_itr in range(p):
	o_count = int(input())
	o = list(map(int, input().rstrip().split()))
	o.sort()
	result = mmmm(o)
	fptr.write(str(result) + '\n')
fptr.close()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import os
import sys

def uG(c):
	aSum = 0
	for i in c:
		aSum ^= int(i)
	if aSum == 0:
		return 0
	print(c)
	divider = 2 ** (len(bin(aSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in c]
	print(modlist)
	if max(modlist) < 0:
		c[c.index(max(c))] += divider
		return divider + uG(c)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	c[modlist.index(increaseNumber)] += increase
	print(c)
	print()
	return increase + uG(c)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	c = list(map(int, input().rstrip().split()))
	c.sort()
	result = uG(c)
	fptr.write(str(result) + '\n')
fptr.close()


import os
import sys

def uG(p):
	aSum = 0
	for i in p:
		aSum ^= int(i)
	if aSum == 0:
		return 0
	print(p)
	divider = 2 ** (len(bin(aSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in p]
	print(modlist)
	if max(modlist) < 0:
		p[p.index(max(p))] += divider
		return divider + uG(p)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	p[modlist.index(increaseNumber)] += increase
	print(p)
	print()
	return increase + uG(p)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	c = list(map(int, input().rstrip().split()))
	c.sort()
	result = uG(c)
	fptr.write(str(result) + '\n')
fptr.close()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
SUNNY = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	SUNNY.write(str(result) + '\n')
SUNNY.close()


import os
import sys

def unfairGame(T):
	nimSum = 0
	for i in T:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(T)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in T]
	print(modlist)
	if max(modlist) < 0:
		T[T.index(max(T))] += divider
		return divider + unfairGame(T)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	T[modlist.index(increaseNumber)] += increase
	print(T)
	print()
	return increase + unfairGame(T)
SDF = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	T_count = int(input())
	T = list(map(int, input().rstrip().split()))
	T.sort()
	result = unfairGame(T)
	SDF.write(str(result) + '\n')
SDF.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import os
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
nums = [1, 10, 10, 15, 27, 4, 9, 12, 26, 9, 14, 3, 25, 23, 3, 10, 3, 5, 13, 18]
for i in nums:
	print(i)
for t_itr in range(t):
	s_count = int(input())
	s = list(map(int, input().rstrip().split()))
	s.sort()
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import math
import os
import random
import re
import sys

def unfairGame(s):
	nimSum = 0
	for i in s:
		nimSum ^= int(i)
	if nimSum == 0:
		return 0
	print(s)
	divider = 2 ** (len(bin(nimSum)) - 3)
	print(divider)
	modlist = [x % divider if x % (2 * divider) < divider else -1 for x in s]
	print(modlist)
	if max(modlist) < 0:
		s[s.index(max(s))] += divider
		return divider + unfairGame(s)
	increaseNumber = max(modlist)
	increase = divider - increaseNumber
	print(increase)
	s[modlist.index(increaseNumber)] += increase
	print(s)
	print()
	return increase + unfairGame(s)
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
	s_count = int(input().strip())
	s = list(map(int, input().rstrip().split()))
	result = unfairGame(s)
	fptr.write(str(result) + '\n')
fptr.close()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()


import operator
from functools import reduce

def xor(nums):
	return reduce(operator.xor, nums, 0)

def lowZero(v):
	p = 0
	while True:
		m = 1 << p
		if v & m == 0:
			return p
		p += 1

def highOne(v):
	p = 0
	high = None
	while v != 0:
		m = 1 << p
		if v & m != 0:
			high = p
			v &= ~m
		p += 1
	return high

def zeroAt(v, p):
	return v & 1 << p == 0

def diffToFlip(v, p):
	t = 1 << p
	r = v + t & ~(t - 1)
	return r - v

def lowPosWithMoreThanOneZero(nums):
	p = 0
	while True:
		m = 1 << p
		n = sum((1 if v & m == 0 else 0 for v in nums))
		if n > 1:
			return p
		p += 1

def pairs(n):
	return ((i, j) for i in range(0, n - 1) for j in range(i + 1, n))

def fixPiles(piles):
	highOneP = highOne(xor(piles))
	if highOneP == None:
		r = piles
	elif any((zeroAt(v, highOneP) for v in piles)):
		r = fixPilesWithZeroAtHigh(piles)
	else:
		r = fixPilesWithoutZeroAtHigh(piles, highOneP)
	return r

def fixPilesWithZeroAtHigh(piles):
	piles = list(piles)
	while True:
		highOneP = highOne(xor(piles))
		if highOneP == None:
			return piles
		candidates = [(i, diffToFlip(v, highOneP)) for (i, v) in enumerate(piles) if zeroAt(v, highOneP)]
		winner = min(candidates, key=operator.itemgetter(1))
		(i, add) = winner
		piles[i] += add
	return piles

def fixPilesWithoutZeroAtHigh(piles, highOneP):
	highPiles = [v >> highOneP + 1 for v in piles]
	highPilesZ = [(v, lowZero(v)) for v in highPiles]
	matches = [(i, j, highOneP + 1 + highPilesZ[i][1]) for (i, j) in pairs(len(piles)) if highPilesZ[i][1] == highPilesZ[j][1]]
	if not matches:
		zeroP = lowPosWithMoreThanOneZero(highPiles)
		lowzs = [i for (i, v) in enumerate(highPiles) if zeroAt(v, zeroP)]
		nz = len(lowzs)
		baseZeroP = highOneP + 1 + zeroP
		matches = [(lowzs[i], lowzs[j], baseZeroP) for (i, j) in pairs(nz)]
	results = (fixPilesTwoZeros(piles, zeroP, i, j) for (i, j, zeroP) in matches)
	return min(results, key=sum)

def fixPilesTwoZeros(piles, zeroP, i, j):
	iAdd = diffToFlip(piles[i], zeroP)
	jAdd = diffToFlip(piles[j], zeroP)
	piles = list(piles)
	piles[i] += iAdd
	piles[j] += jAdd
	return fixPilesWithZeroAtHigh(piles)

def solve(piles):
	fixedPiles = fixPiles(piles)
	return (sum(fixedPiles) - sum(piles), fixedPiles)

def readLine():
	return input()

def readInt():
	return int(readLine())

def readInts():
	return tuple((int(token) for token in readLine().split()))

def readIntList():
	return list(readInts())

def main():
	nt = readInt()
	for _ in range(nt):
		_n = readInt()
		piles = readIntList()
		(answer, _fixedPiles) = solve(piles)
		print(answer)
main()