Among Johnny's numerous hobbies, there are two seemingly harmless ones: applying bitwise operations and sneaking into his dad's office. As it is usually the case with small children, Johnny is unaware that combining these two activities can get him in a lot of trouble.

There is a set $S$ containing very important numbers on his dad's desk. The minute Johnny heard about it, he decided that it's a good idea to choose a positive integer $k$ and replace each element $s$ of the set $S$ with $s \oplus k$ ($\oplus$ denotes the exclusive or operation). 

Help him choose such $k$ that Johnny's dad will not see any difference after his son is done playing (i.e. Johnny will get the same set as before playing). It is possible that no such number exists. It is also possible that there are many of them. In such a case, output the smallest one. Note that the order of elements in a set doesn't matter, i.e. set $\{1, 2, 3\}$ equals to set $\{2, 1, 3\}$.

Formally, find the smallest positive integer $k$ such that $\{s \oplus k | s \in S\} = S$ or report that there is no such number.

For example, if $S = \{1, 3, 4\}$ and $k = 2$, new set will be equal to $\{3, 1, 6\}$. If $S = \{0, 1, 2, 3\}$ and $k = 1$, after playing set will stay the same.


-----Input-----

In the first line of input, there is a single integer $t$ ($1 \leq t \leq 1024$), the number of test cases. In the next lines, $t$ test cases follow. Each of them consists of two lines. 

In the first line there is a single integer $n$ ($1 \leq n \leq 1024$) denoting the number of elements in set $S$. Second line consists of $n$ distinct integers $s_i$ ($0 \leq s_i < 1024$), elements of $S$.

It is guaranteed that the sum of $n$ over all test cases will not exceed $1024$.


-----Output-----

Print $t$ lines; $i$-th line should contain the answer to the $i$-th test case, the minimal positive integer $k$ satisfying the conditions or $-1$ if no such $k$ exists.


-----Example-----
Input
6
4
1 0 2 3
6
10 7 14 8 3 12
2
0 2
3
1 2 3
6
1 4 6 10 11 12
2
0 1023

Output
1
4
2
-1
-1
1023



-----Note-----

In the first test case, the answer is $1$ because it is a minimum positive integer and it satisfies all the conditions.

Difficulty: interview

Starter code:

Solutions:
t = int(input())

for _ in range(t):
    n = list(input().strip())
    s = list(map(int, input().strip().split()))

    check = set(s)
    found = False
    for i in range(1, 1025):
        newset = set([e^i for e in s])
        if check == newset:
            print(i)
            found = True
            break
    if not found:
        print(-1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
  N = int(input())
  a = list(map(int, input().split()))
  a.sort()
  for x in range(1, 1024):
    b = [0] * N
    for i in range(N): b[i] = a[i] ^ x
    b.sort()
    if a == b:
      print(x)
      break
  else: print(-1)

import sys
input = sys.stdin.readline


t = int(input())
for _ in range(t):
    n = int(input())
    S = set(map(int, input().split()))
    ok = False
    for i in range(1, 1024):
        tmp = {i ^ val for val in S}
        if tmp == S:
            print(i)
            ok = True
            break
    if not ok:
        print(-1)


for _ in range(int(input())):
    n=int(input())
    s=list(map(int,input().split()))
    ans=-1
    for k in range(1,1025):
        st=set(s)
        for i in s:
            val=i^k 
            if val not in st:
                break
            st.remove(val)
        if not st:
            ans=k 
            break
    print(ans)

# from decorators import *
from sys import stdin, stdout
from math import ceil

# @debug
def solve(n,s):
    s.sort()
    for i in range(1,1025):
        b = []
        for j in range(n):
            b.append(s[j]^i)
        b.sort()
        flag = True
        for j in range(n):
            if s[j]!=b[j]:
                flag = False
                break
        if flag:
            print(i)
            return True
    print(-1)

for _ in range(int(input())):
    n = int(stdin.readline())
    s = list(map(int,stdin.readline().split()))
    solve(n,s)

t = int(input())

for k in range(t):
    n = int(input())
    a = set(map(int, input().split()))
    for x in range(1, 1025):
        if set(x ^ q for q in a) == a:
            print(x)
            break 
    else:
        print(-1)

import sys
ints = (int(x) for x in sys.stdin.read().split())
sys.setrecursionlimit(3000)

def main():
    ntc = next(ints)
    for tc in range(1,ntc+1):
        n = next(ints)
        s = [next(ints) for i in range(n)]
        P = None
        for x in s:
            p = set(x^y for y in s)
            if P==None: P = p
            else: P &= p
        ans = next(iter(sorted(P)[1:]), -1)
        print(ans)
    return

main()


T = int(input())

for t in range(T):
    n = int(input())
    S = [int(_) for _ in input().split()]
    setS = set(S)

    for k in range(1, 1025):
        for el in setS:
            if el ^ k not in setS:
                break
        else:
            print(k)
            break
    else:
        print(-1)


for _ in range(int(input())):
    n = int(input())
    ans = -1
    l = set(map(int,input().split()))
    for i in range(1,4 * (10 ** 3)):
        s1 = set()
        for j in l:
            s1.add(i ^ j)
        if(s1 == l):
            ans = i
            break
    print(ans)

import sys
def arr():
    return list(map(int,input().split()))
input=sys.stdin.readline
from collections import defaultdict
import math
for _ in range(int(input())):
    N=int(input())
    L=arr()
    L.sort()
    flag=False
    for i in range(1,1025):
        x=L[::]
        for j in range(N):
            x[j]=x[j]^i
        x.sort()
        x.sort()
        if x==L:
            ans=i
            flag=True
            break
    if flag:
        print(ans)
    else:
        print(-1)