human
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 ⊕ k (⊕ denotes the [exclusive or](https://en.wikipedia.org/wiki/Exclusive_or#Computer_science) 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 ⊕ k | s ∈ 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 ≤ t ≤ 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 ≤ n ≤ 1024) denoting the number of elements in set S. Second line consists of n distinct integers s_i (0 ≤ 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...
Solve the task in PYTHON.
 What is a Python code to find the smallest positive integer k such that \\{s ⊕ k | s ∈ S\} = S or report that there is no such number?
assistant
#Here is Python code to find the smallest positive integer k such that \\{s ⊕ k | s ∈ S\} = S or report that there is no such number.

from __future__ import division, print_function

def main():
    # Template 1.0
    import sys, re, math
    from collections import deque, defaultdict, Counter, OrderedDict
    from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
    from heapq import heappush, heappop, heapify, nlargest, nsmallest
    def STR(): return list(input())
    def INT(): return int(input())
    def MAP(): return map(int, input().split())
    def LIST(): return list(map(int, input().split()))
    def list2d(a, b, c): return [[c] * b for i in range(a)]
    def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
    def sortDictWithVal(passedDic):
        temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]
        toret = {}
        for tup in temp:
            toret[tup[0]] = tup[1]
        return toret
    def sortDictWithKey(passedDic):
        return dict(OrderedDict(sorted(passedDic.items())))
 
    INF = float('inf')
    mod = 10 ** 9 + 7
    
    def same(a1,a2):
        for i in range(len(a1)):
            if(a1[i]!=a2[i]):
                return False
        return True
    
    
    t = INT()
    
    while (t != 0):
        n = INT()
        a = LIST()
    
        a.sort()
    
        flag = 0
        for k in range(1, 2048):
            temp = []
            for el in a:
                temp.append(el^k)
            temp.sort()
            if(same(temp, a)):
                flag = 1
                break
        if(flag==1):
            print(k)
        else:
            print(-1)
    
        t -= 1
    



######## Python 2 and 3 footer by Pajenegod and c1729

# Note because cf runs old PyPy3 version which doesn't have the sped up
# unicode strings, PyPy3 strings will many times be slower than pypy2.
# There is a way to get around this by using binary strings in PyPy3
# but its syntax is different which makes it kind of a mess to use.

# So on cf, use PyPy2 for best string performance.

py2 = round(0.5)
if py2:
    from future_builtins import...