Read problems statements in Mandarin Chinese  and Russian. 

You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.

Given an integer K, what is the maximum value of K ⊕ F(P), over all possible subsets P of A?

------ Input ------ 

The first line contains T, the number of test cases. Each test case consists of N and K in one line, followed by the array A in the next line.

------ Output ------ 

For each test case, print the required answer in one line.

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

$1 ≤ T ≤ 10$
$1 ≤ K, A_{i} ≤ 1000$
$Subtask 1 (30 points):1 ≤ N ≤ 20$
$Subtask 2 (70 points):1 ≤ N ≤ 1000$
 
----- Sample Input 1 ------ 
1
3 4
1 2 3
----- Sample Output 1 ------ 
7
----- explanation 1 ------ 

Considering all subsets:
F({}) = 0 ? 4 ? 0 = 4
F({1}) = 1 ? 4 ? 1 = 5
F({1,2}) = 3 ? 4 ? 3 = 7
F({1,3}) = 2 ? 4 ? 2 = 6
F({1,2,3}) = 0 ? 4 ? 0 = 4
F({2}) = 2 ? 4 ? 2 = 6
F({2,3}) = 1 ? 4 ? 1 = 5
F({3}) = 3 ? 4 ? 3 = 7
Therefore, the answer is 7.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Bit manipulation

String algorithms

Dynamic programming

Mathematics

Data structures


Solutions:
for t in range(0, int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))[:n]
	N = 1024
	dp = [0] * 1024
	dp[0] = 1
	for i in range(0, n):
		for j in range(0, N):
			if dp[j] == 1:
				value = j ^ arr[i]
				dp[value] = 1
	ans = 0
	for i in range(0, N):
		if dp[i] == 1:
			ans = max(ans, i ^ k)
	print(ans)


import sys
sys.setrecursionlimit(10 ** 6)

def max_xor(i, K, N, A, D):
	if i == N:
		return K
	elif (i, K) in D:
		return D[i, K]
	else:
		D[i, K] = max(max_xor(i + 1, K, N, A, D), max_xor(i + 1, K ^ A[i], N, A, D))
		return D[i, K]
T = int(input())
ans = []
for _ in range(T):
	(N, K) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	ans.append(max_xor(0, K, N, A, {}))
for i in ans:
	print(i)


import sys
sys.setrecursionlimit(10 ** 6)

def fun(i, ar, k, n, d):
	if i == n:
		return k
	elif (i, k) in d:
		return d[i, k]
	else:
		d[i, k] = max(fun(i + 1, ar, k ^ ar[i], n, d), fun(i + 1, ar, k, n, d))
		return d[i, k]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = [int(x) for x in input().split()]
	print(fun(0, ar, k, n, {}))


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	N = 1023
	dp = [0] * (N + 1)
	dp[0] = 1
	for i in range(n):
		for j in range(N + 1):
			x = j ^ arr[i]
			if dp[j] == 1:
				dp[x] = 1
	Max = 0
	for i in range(N + 1):
		if dp[i] == 1:
			Max = max(Max, i ^ k)
	print(Max)


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

def readint():
	return int(read())
t = readint()
for i in range(t):
	(n, k) = map(int, read().split())
	arr = [0] * 1025
	a = [int(x) for x in read().split()]
	for x in a:
		arr[x] = 1
	maxvalue = k
	for x in a:
		for j in range(1024):
			if arr[j] == 1:
				exor = x ^ j
				arr[exor] = 1
	for j in range(1024):
		if arr[j] == 1:
			maxvalue = max(maxvalue, j ^ k)
	print(maxvalue)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))
	dp = []
	for i in range(n):
		dp.append([])
		for j in range(1024):
			dp[i].append(0)
	dp[0][0] = 1
	dp[0][a[0]] = 1
	for i in range(1, n):
		for j in range(1024):
			if dp[i - 1][j]:
				dp[i][j] = dp[i - 1][j]
				dp[i][j ^ a[i]] = dp[i - 1][j]
	ma = 0
	val = n - 1
	for i in range(1024):
		if dp[val][i]:
			ma = max(ma, k ^ i)
	print(ma)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	W = [int(x) for x in input().split()]
	S = {k}
	for i in W:
		_t = []
		for j in S:
			_t.append(i ^ j)
		for x in _t:
			S.add(x)
	print(max(S))


t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ad = set(arr)
	w = set()
	w = []
	w.append(k)
	ans = k
	v = set()
	v.add(k)
	for i in ad:
		for j in range(len(w)):
			x = w[j] ^ i
			ans = max(ans, x)
			v.add(x)
		w = v
		w = list(w)
	print(ans)


T = int(input())
for _ in range(T):
	[n, k] = [int(s) for s in input().split()]
	a = [int(s) for s in input().split()]
	dp = [[0] * 1024] * (n + 1)
	for i in range(n + 1):
		for j in range(1024):
			dp[i][j] = 0
	dp[0][0] = 1
	for i in range(1, n + 1):
		for j in range(1024):
			dp[i][j] = dp[i - 1][j] or dp[i - 1][a[i - 1] ^ j]
	res = 0
	for j in range(1024):
		res = max(res, dp[n][j] * (j ^ k))
	print(res)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	dp = [[0 for i in range(1024)] for j in range(n + 1)]
	dp[0][0] = 1
	for i in range(1, n + 1):
		for j in range(1024):
			dp[i][j] = dp[i - 1][j] | dp[i - 1][j ^ l[i - 1]]
	maxo = 0
	for j in range(1023, -1, -1):
		if dp[n][j] == 1:
			maxo = max(maxo, j ^ k)
	print(maxo)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dp = [[0] * 1024 for i in range(n + 1)]
	dp[0][0] = 1
	for i in range(1, n + 1):
		for j in range(1024):
			dp[i][j] = dp[i - 1][j] | dp[i - 1][j ^ a[i - 1]]
	ans = 0
	for i in range(1024):
		ans = max(ans, dp[n][i] * (i ^ k))
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	dp = [0] * 1025
	dp[0] = 1
	for i in arr:
		for j in range(1024):
			if dp[j]:
				dp[j ^ i] = 1
	ans = 0
	for i in range(1024):
		if dp[i]:
			ans = max(ans, i ^ k)
	print(ans)


import sys
sys.setrecursionlimit(10 ** 6)

def rec(i, xor):
	if i >= n:
		return xor
	if (i, xor) in dp:
		return dp[i, xor]
	dp[i, xor] = max(rec(i + 1, xor ^ a[i]), rec(i + 1, xor))
	return dp[i, xor]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dp = {}
	ans = rec(0, k)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(i) for i in input().split()]
	ans = k
	s = {k}
	for i in l:
		temp = set()
		for j in s:
			curr = i ^ j
			ans = max(curr, ans)
			temp.add(curr)
		s = s | temp
	print(ans)


for tnum in range(int(input())):
	(nvar, kvar) = map(int, input().strip().split(' '))
	elarr = []
	elarr = [int(elem) for elem in input().strip().split(' ')]
	dp = [False] * 1024
	dp[0] = True
	for iterv in range(nvar):
		for jterv in range(1024):
			dp[jterv ^ elarr[iterv]] = dp[jterv ^ elarr[iterv]] | dp[jterv]
	ans = kvar
	for iterv in range(1024):
		if dp[iterv]:
			ans = max(iterv ^ kvar, ans)
	print(ans)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	dp = [[0 for i in range(1024)] for j in range(1024)]
	dp[0][0] = 1
	for i in range(1, n + 1):
		for j in range(1024):
			dp[i][j] = dp[i - 1][j] | dp[i - 1][j ^ l[i - 1]]
	print(max([dp[n][j] * (j ^ k) for j in range(1024)]))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	a = set()
	a.add(k)
	for i in l:
		c = a.copy()
		for j in c:
			a.add(i ^ j)
	print(max(a))


test = int(input())
for _ in range(test):
	(n, k) = map(int, input().split())
	x = list(map(int, input().split()))
	z = {k}
	for i in x:
		t = []
		for k in z:
			t.append(i ^ k)
		for k in t:
			z.add(k)
	print(max(z))


t = int(input())
for i in range(t):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	n = 1023
	dp = [0] * (n + 1)
	dp[0] = 1
	for i in range(N):
		for j in range(n + 1):
			x = j ^ A[i]
			if dp[j] == 1:
				dp[x] = 1
	Max = 0
	for i in range(n + 1):
		if dp[i] == 1:
			Max = max(Max, i ^ K)
	print(Max)


for _ in range(int(input().strip())):
	(n, k) = map(int, input().strip().split())
	lst = list(map(int, input().strip().split()))
	Matrix = [[0 for x in range(1024)] for y in range(n + 1)]
	for i in lst:
		Matrix[1][i] = 1
	for i in range(2, n + 1):
		for j in range(1024):
			if Matrix[i - 1][j]:
				Matrix[i][j] = 1
			elif Matrix[i - 1][lst[i - 1] ^ j]:
				Matrix[i][j] = 1
	master_max = k
	for i in range(1024):
		master_max = max(master_max, (k ^ i) * Matrix[n][i])
	print(master_max)


T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	arr = [0] + [int(_) for _ in input().split()]
	ans = 0
	check = [0 for _ in range(1024)]
	check[0] = 1
	for i in range(1, n + 1):
		for j in range(1024):
			index = j ^ arr[i]
			if check[j]:
				check[index] = 1
	for i in range(1024):
		if check[i]:
			ans = max(ans, k ^ i)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [*map(int, input().split())]
	s = set([0])
	for i in a:
		e = set(s)
		for x in s:
			e.add(x ^ i)
		s = e
	mx = k
	for i in s:
		mx = max(mx, i ^ k)
	print(mx)


from collections import defaultdict as dd
for _ in range(int(input())):

	def GaussianElimination(nums, k):

		def length(num):
			count = 0
			while num:
				num >>= 1
				count += 1
			return count
		d = dd(list)
		for num in nums:
			l = length(num)
			d[l].append(num)
		modified_array = []
		for i in reversed(range(64)):
			if d[i]:
				first = d[i][0]
				modified_array.append(first)
				for j in range(1, len(d[i])):
					temp = first ^ d[i][j]
					l = length(temp)
					d[l].append(temp)
		ans = k
		for num in modified_array:
			ans = max(ans, ans ^ num)
		return ans
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	print(GaussianElimination(nums, k))


T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dp = []
	dp = [0] * 1024
	dp[0] = 1
	dp1 = []
	dp1 = [dp] * (n + 1)
	for i in range(1, n + 1):
		for j in range(1024):
			if dp1[i - 1][j] == 1 or dp1[i - 1][j ^ a[i - 1]] == 1:
				dp1[i][j] = 1
	ans = k
	for i in range(1024):
		if dp1[n][i] == 1:
			ans = max(ans, k ^ i)
	print(ans)


for _ in range(int(input())):
	(array_size, k) = map(int, input().split())
	array = map(int, input().split())
	possible_xors = [False] * 1024
	possible_xors[0] = True
	for element in array:
		for i in range(1024):
			possible_xors[i] = possible_xors[i] or possible_xors[i ^ element]
	max_value = k
	for i in range(1024):
		if possible_xors[i]:
			max_value = max(max_value, i ^ k)
	print(max_value)


raw_input = input
for _ in range(int(raw_input())):
	(n, k) = map(int, raw_input().split())
	A = [int(x) for x in raw_input().split()]
	dp = [False] * 1024
	dp[k] = True
	for i in A:
		dp[i ^ k] = True
		for j in range(1024):
			if dp[j]:
				dp[j ^ i] = True
	for i in range(1023, -1, -1):
		if dp[i]:
			print(i)
			break


t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	dp = [0] * 1024
	dp[0] = True
	for i in range(len(arr)):
		for j in range(0, 1024):
			dp[arr[i] ^ j] |= dp[j]
	ans = k
	for i in range(0, 1024):
		if dp[i]:
			ans = max(ans, k ^ i)
	print(ans)


import sys
sys.setrecursionlimit(10 ** 9)

def rec(a, i, curr, k, dp):
	global mxor
	if i >= len(a) - 1:
		mxor = max(mxor, k ^ curr)
		return mxor
	if (curr, i) in dp:
		return dp[curr, i]
	for j in range(i + 1, len(a)):
		curr ^= a[j]
		r1 = rec(a, j, curr, k, dp)
		curr ^= a[j]
		r2 = rec(a, j, curr, k, dp)
	dp[curr, i] = max(r1, r2)
	return dp[curr, i]

def calc_max(n):
	n -= 1
	n |= n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	return n
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	mxor = 0
	mmxor = 1025
	dp = [[0 for i in range(mmxor)] for j in range(n + 1)]
	dp[0][0] = 1
	for i in range(1, n + 1):
		for j in range(mmxor):
			x = a[i - 1]
			dp[i][j] = dp[i - 1][j] | dp[i][j]
			if dp[i][j]:
				dp[i][j ^ x] = 1
	for (i, v) in enumerate(dp[-1]):
		if v:
			mxor = max(mxor, i ^ k)
	print(mxor)


import functools
from sys import stdin

def powerset(lst):
	return functools.reduce(lambda result, x: result + [subset + [x] for subset in result], lst, [[]])
tc = int(stdin.readline())
for i in range(tc):
	(n, k) = map(int, stdin.readline().split())
	list1 = list(set(map(int, stdin.readline().split())))
	dp = [[0] * 1024 for x in range(n + 1)]
	dp[0][0] = 1
	n = len(list1)
	for i in range(1, n + 1):
		for j in range(0, 1024):
			dp[i][j] = dp[i - 1][j] + dp[i - 1][j ^ list1[i - 1]]
	n_list = [x for x in dp[n]]
	maxi = 0
	for (i, each) in enumerate(dp[n]):
		if each > 0 and maxi < i ^ k:
			maxi = i ^ k
	print(maxi)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ls = list(map(int, input().split()))
	dp = [False] * 1024
	dp[0] = True
	for i in range(n):
		for j in range(1024):
			dp[j ^ ls[i]] = dp[j ^ ls[i]] | dp[j]
	dp = [i ^ k for i in range(1024) if dp[i]]
	print(max(dp))


t = int(input())
while t:
	n_k = [int(i) for i in input().split()]
	n = n_k[0]
	k = n_k[1]
	arr = [int(i) for i in input().split()]
	msb = max(arr)
	index = 0
	for i in range(31, -1, -1):
		maxInd = index
		maxEle = -2147483648
		for j in range(index, n):
			if arr[j] & 1 << i != 0 and arr[j] > maxEle:
				maxEle = arr[j]
				maxInd = j
		if maxEle == -2147483648:
			continue
		temp = arr[index]
		arr[index] = arr[maxInd]
		arr[maxInd] = temp
		maxInd = index
		for j in range(n):
			if j != maxInd and arr[j] & 1 << i != 0:
				arr[j] = arr[j] ^ arr[maxInd]
		index = index + 1
	res = k
	for i in range(n):
		if res < res ^ arr[i]:
			res = res ^ arr[i]
	print(res)
	t -= 1


__author__ = 'Ronald Kaiser'
__email__ = 'raios dot catodicos at gmail dot com'

def solve(A, K):
	(m, n) = (len(A), 2 ** len(bin(max(max(A), K))[2:]))
	dp = [[False for _ in range(n)] for _ in range(m)]
	dp[0][0] = True
	maxi = 0
	for i in range(1, m):
		for j in range(n):
			dp[i][j] = dp[i - 1][j] or dp[i - 1][A[i] ^ j]
			if dp[i][j]:
				maxi = max(j ^ K, maxi)
	return maxi
for _ in range(int(input())):
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	print(solve([0] + A, K))


t = int(input())
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	temp = [[0 for i in range(1024)] for i in range(n + 1)]
	temp[0][0] = 1
	for i in range(1, n + 1):
		for j in range(1024):
			temp[i][j] = temp[i - 1][j] or temp[i - 1][j ^ arr[i - 1]]
	maxx = -float('inf')
	for i in range(1024):
		if temp[n][i] == 1:
			maxx = max(maxx, k ^ i)
	print(maxx)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	dp = [[0] * 1024 for _ in range(n + 1)]
	dp[0][0] = 1
	for i in range(len(A)):
		dp[i][0] = 1
	for elem in A:
		dp[1][elem] = 1
	for i in range(1, n + 1):
		for j in range(1024):
			dp[i][j] = dp[i - 1][j] or dp[i - 1][j ^ A[i - 1]]
	maxi = 0
	for i in range(1024):
		if dp[n][i]:
			maxi = max(maxi, i ^ k)
	print(maxi)


def solve():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = {0}
	for i in range(n):
		temp = {0}
		for j in ans:
			temp.update({arr[i] ^ j})
		temp.update({arr[i]})
		ans.update(temp)
	ans_1 = 0
	ans = list(ans)
	for m in ans:
		if ans_1 < m ^ k:
			ans_1 = m ^ k
	print(ans_1)
t = int(input())
while t != 0:
	solve()
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(o) for o in input().split()]
	dp = [False] * 1024
	dp[0] = True
	for x in a:
		for i in range(1024):
			dp[i ^ x] = dp[i] or dp[i ^ x]
	ma = k
	for i in range(1024):
		if dp[i]:
			ma = max(ma, i ^ k)
	print(ma)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	ans = k
	s = {k}
	for i in ar:
		temp = set()
		for j in s:
			cur = i ^ j
			ans = max(ans, cur)
			temp.add(cur)
		s = s | temp
	print(ans)


t = int(input())
for T in range(t):
	s = []
	e = []
	s = list(map(int, input().split()))
	e = list(map(int, input().split()))
	dp = [False] * 1024
	dp[0] = True
	for i in e:
		for x in range(int(1024)):
			if dp[x]:
				dp[x ^ i] = True
	ans = 0
	for i in range(1024):
		if dp[i]:
			ans = max(i ^ s[1], ans)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [*map(int, input().split())]
	dp = [[False] * 1024 for _ in range(n + 1)]
	dp[0][0] = True
	for i in range(1, n + 1):
		for j in range(0, 1024):
			dp[i][j] = dp[i - 1][j] | dp[i - 1][j ^ a[i - 1]]
	mx = k
	for i in range(1024):
		if dp[n][i]:
			mx = max(mx, i ^ k)
	print(mx)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	some = list(map(int, input().split()))
	some1 = set()
	some1.add(k)
	for i in some:
		some2 = set()
		for j in some1:
			some2.add(i ^ j)
		for j in some2:
			some1.add(j)
	print(max(some1))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [False] * 1024
	b[0] = True
	for elements in a:
		for j in range(1024):
			b[j] = b[j] or b[j ^ elements]
	max_value = k
	for i in range(1024):
		if b[i]:
			max_value = max(max_value, i ^ k)
	print(max_value)


import sys
sys.setrecursionlimit(10 ** 7)

class Codechef:
	dp = []

	def __init__(self):
		self.dp = [-1] * 1024
		self.dp = [self.dp] * 1024

	def maxXor(self, arr, n, k):
		if n == 0:
			return k
		if self.dp[n][k] != -1:
			return self.dp[n][k]
		self.dp[n][k] = max(self.maxXor(arr, n - 1, k ^ arr[n - 1]), self.maxXor(arr, n - 1, k))
		return self.dp[n][k]
T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	c = Codechef()
	arr = list(map(int, input().split()))
	print(c.maxXor(arr, n, k))


from math import log, floor
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	(row, col) = (0, int(floor(log(arr[0], 2))))
	while row < N and col >= 0:
		pivot = None
		colval = 1 << col
		for i in range(row, N):
			if arr[i] & colval:
				pivot = i
				break
		if pivot == None:
			col -= 1
			continue
		if pivot != row:
			(arr[pivot], arr[row]) = (arr[row], arr[pivot])
		for i in range(row + 1, N):
			if arr[i] & colval:
				arr[i] ^= arr[row]
		row += 1
		col -= 1
	ans = K
	for val in arr:
		ans = max(ans, ans ^ val)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().strip().split())
	S = list(map(int, input().strip().split()))
	dp = [0 for i in range(1024)]
	dp[0] = True
	for i in range(n):
		for j in range(1024):
			dp[j ^ S[i]] |= dp[j]
	ans = k
	for i in range(1024):
		if dp[i]:
			ans = max(ans, k ^ i)
	print(ans)


def solve():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	vis = set()
	vis.add(k)
	for i in arr:
		temp = set()
		for j in vis:
			temp.add(i ^ j)
		vis = vis.union(temp)
	print(max(vis))
for t in range(int(input())):
	solve()


from collections import defaultdict
T = int(input())
output = []
for _ in range(T):
	(N, K) = map(int, input().split())
	As = list(map(int, input().split()))
	dp = [[0 for _ in range(1024)] for _ in range(N + 1)]
	dp[0][0] = 1
	for i in range(1, N + 1):
		for j in range(1024):
			dp[i][j] = dp[i - 1][j] | dp[i - 1][j ^ As[i - 1]]
	max_v = -1
	for j in range(1024):
		if dp[N][j] == 1:
			max_v = max(K ^ j, max_v)
	output.append(max_v)
for o in output:
	print(o)


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

def lst():
	return list(mp())
for _ in range(int(input())):
	(n, k) = mp()
	a = lst()
	pre = [0 for i in range(n)]
	pre[0] = a[0]
	h = [0 for i in range(2026)]
	h[0] = 1
	for i in range(n):
		h[a[i]] = 1
		for j in range(1024):
			if h[j] == 1:
				h[a[i] ^ j] = 1
	for i in range(1024, -1, -1):
		e = k ^ i
		if h[e] == 1:
			print(i)
			break


for z in range(int(input())):
	(n, k) = tuple(map(int, input().split()))
	ar = list(map(int, input().split()))
	dp = [[0 for i in range(1024)] for j in range(n + 1)]
	dp[0][0] = 1
	for i in range(1, n + 1):
		for j in range(1024):
			dp[i][j] = dp[i - 1][j] or dp[i - 1][ar[i - 1] ^ j]
	sol = [dp[n][j] * (j ^ k) for j in range(1024)]
	print(max(sol))


for tc in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	a = set()
	a.add(k)
	for i in l:
		temp = a.copy()
		for j in temp:
			a.add(i ^ j)
	print(max(a))


for i in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	l = list(map(int, input().split()))
	s = {k}
	for i in l:
		a = []
		for j in s:
			a.append(j ^ i)
		for d in a:
			s.add(d)
	print(max(s))


def calc(arr, k):
	dp = [0] * 1024
	dp[0] = 1
	for ele in arr:
		for j in range(1023, -1, -1):
			neval = j ^ ele
			if dp[j]:
				dp[neval] = 1
	ans = k
	for i in range(1024):
		if dp[i]:
			ans = max(ans, i ^ k)
	return ans
t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = calc(arr, k)
	print(ans)
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	dp = [0 for i in range(1024)]
	dp[0] = 1
	l = list(map(int, input().split()))
	for i in l:
		for j in range(1024):
			if dp[j]:
				val = i ^ j
				dp[val] = 1
	ans = k
	for i in range(1024):
		if dp[i]:
			ans = max(ans, i ^ k)
	print(ans)


t = int(input())
for i in range(t):
	(n, p) = map(int, input().split())
	a = list(map(int, input().split()))
	m = [[0] * 1024 for x in range(n + 1)]
	m[0][0] = 1
	max1 = 0
	for j in range(1, n + 1):
		for k in range(0, 1024):
			m[j][k] = m[j - 1][k] + m[j - 1][k ^ a[j - 1]]
	for (j, each) in enumerate(m[n]):
		if each > 0 and max1 < j ^ p:
			max1 = j ^ p
	print(max1)


t = int(input())
for i in range(0, t):
	(n, b) = map(int, input().split())
	li = [int(k) for k in input().split()]
	dp = [False] * 1024
	dp[0] = True
	for j in range(0, len(li)):
		for l in range(0, 1023):
			dp[l ^ li[j]] = dp[l ^ li[j]] | dp[l]
	ans = 0
	for a in range(0, 1024):
		if dp[a]:
			ans = max(ans, b ^ a)
	print(ans)


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	dp = [[0] * 1024 for i in range(n + 1)]
	dp[0][0] = 1
	for i in range(1, n + 1):
		for j in range(1024):
			if dp[i - 1][j] == 1:
				dp[i][j] = 1
				dp[i][a[i - 1] ^ j] = 1
	m = k
	for i in range(1024):
		if dp[n][i] == 1:
			m = max(m, k ^ i)
	print(m)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(i) for i in input().split()]
	dp = [0] * 1024
	dp[0] = 1
	for i in range(n):
		for j in range(1024):
			dp[j ^ l[i]] = dp[j] | dp[j ^ l[i]]
	maxi = 0
	for i in range(1024):
		if dp[i]:
			maxi = max(maxi, i ^ k)
	print(maxi)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = [0] * 1024
	for i in a:
		ans[i] = 1
	for i in range(1024):
		for j in range(1024):
			if ans[i] and ans[j]:
				ans[i ^ j] = 1
	maxi = 0
	for i in range(1024):
		if ans[i] == 1:
			maxi = max(maxi, i ^ k)
	print(maxi)


def answer():
	dp = [[False for i in range(1025)] for i in range(n + 1)]
	dp[0][0] = True
	for i in range(1, n + 1):
		for j in range(1025):
			dp[i][j] = dp[i][j] | dp[i - 1][j]
			if dp[i][j]:
				dp[i][j ^ a[i - 1]] = True
	ans = 0
	for i in range(1025):
		if dp[-1][i]:
			ans = max(ans, i ^ k)
	return ans
for T in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	print(answer())


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ad = set(arr)
	w = [k]
	ans = k
	v = set()
	v.add(k)
	for i in ad:
		for j in range(len(w)):
			x = w[j] ^ i
			ans = max(ans, x)
			v.add(x)
		w = list(v)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	dp = [False] * 1024
	dp[0] = True
	for i in l:
		for j in range(1024):
			dp[i ^ j] = dp[j] or dp[j ^ i]
	ans = k
	for i in range(1024):
		if dp[i]:
			ans = max(ans, k ^ i)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	dp = [[0 for _ in range(1024)] for _ in range(n + 1)]
	dp[0][0] = 1
	ans = k
	for i in range(1, n + 1):
		for j in range(1024):
			dp[i][j] = dp[i - 1][j] | dp[i - 1][j ^ A[i - 1]]
			if i == n and dp[i][j]:
				ans = max(ans, k ^ j)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().strip().split())
	a = list(map(int, input().split()))
	lis = [0 for i in range(1024)]
	lis[0] = True
	for i in range(n):
		for j in range(1024):
			lis[j ^ a[i]] |= lis[j]
	ans = k
	for i in range(1024):
		if lis[i]:
			ans = max(ans, k ^ i)
	print(ans)


t = int(input())
for it in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = set()
	b.add(k)
	for i in a:
		c = b.copy()
		for j in c:
			b.add(i ^ j)
	print(max(b))


for u in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	s = set()
	s.add(k)
	for i in l:
		d = s.copy()
		for j in d:
			s.add(i ^ j)
	print(max(s))


import sys
sys.setrecursionlimit(10 ** 9)

def solve(arr, index, N, K, ans, sub):
	if index < 0:
		return ans ^ K
	if ans in sub[index]:
		return sub[index][ans]
	sub[index][ans] = max(solve(arr, index - 1, N, K, ans, sub), solve(arr, index - 1, N, K, ans ^ arr[index], sub))
	return sub[index][ans]
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	arr = list(map(int, input().split()))
	sub = []
	for i in range(N):
		sub.append({})
	print(max(K, solve(arr, N - 1, N, K, 0, sub)))


for case in range(int(input())):
	(N, K) = map(int, input().split())
	L = list(map(int, input().split()))
	dp = [0] * 1024
	dp[0] = 1
	for i in range(N):
		for j in range(1024):
			dp[L[i] ^ j] |= dp[j]
	ans = K
	for i in range(1024):
		if dp[i]:
			ans = max(ans, K ^ i)
	print(ans)


t = int(input())
for _ in range(t):
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	max_ele = max(A)
	max_len = len(bin(max_ele)) - 2
	buckets = {}
	for j in range(1, max_len + 1):
		buckets[j] = []
	for a in A:
		l = len(bin(a)) - 2
		buckets[l].append(a)
	m_A = []
	for k in reversed(range(1, max_len + 1)):
		if buckets[k] != []:
			temp = buckets[k].pop()
			m_A.append(temp)
			while buckets[k] != []:
				n = buckets[k].pop()
				nx = n ^ temp
				if nx != 0:
					buckets[len(bin(nx)) - 2].append(nx)
	sol = K
	for i in range(len(m_A)):
		if sol ^ m_A[i] > sol:
			sol = sol ^ m_A[i]
	print(sol)