Gwen is good in hacking. She helps Ben and Kevin in many missions. This time the boys need CCTV recordings of a particular area. The security network is secured by a special keyless encryption. When she tries to access the tapes remotely, she sees a series of non-negative integers on screen. By stealing security logs and other information from less protected areas of network, she came to know how to get desired information. The encryption works as follows, it generates a list of non - negative integers and applies a bitwise logical operation i.e AND operation ( & ) on the elements for a valid location on the network in the following way:

There are exactly M + 1 elements in the list and your task is to construct an AND-equation using each element of list exactly once. (That is, M of them will be on the left hand side of the AND-equation and the remaining one will be on the right hand side.) If this is possible, output the value of A[k] in this AND-equation. If no AND-equation can be constructed, output -1. 

The equation can be drawn as follows :

A[0] & A[1] & ....... A[N] = A[k]

Note : It can be shown that for each list there is at most one possible value Y, so the output value is always defined correctly.

Input:
First line consists an integer T, after which T test cases follows.
Each test case's first line contains an integer K denoting the size of list.
After which K integers follows on the next line.

Output:
For each test case output the value of A[k] else -1

Constraints:
0 ≤ A[n] ≤ 10^6
1 ≤ K ≤ 50
1 ≤ T ≤ 10

SAMPLE INPUT
2
3
2 3 7
4
3 9 5 1

SAMPLE OUTPUT
-1
1

Explanation

Test Case #1
No AND Equation is possible in it.

Test Case #2
One And Equation is possible as 3 & 9 & 5 = 1
t=input()
i=0
while i<t:
    n=input()
    x=raw_input().split(' ')
    cnt=0
    j=0
    while j<n:
        el=int(x[j])
        if j==0:
            sm=int(x[1])
        else:
            sm=int(x[0])
        k=0
        while k<n:
            if k!=j:
                sm=sm&int(x[k])
            k=k+1
        if el==sm:
            cnt=1
            break
        j=j+1
    if cnt==1:
        print el
    else:
        print "-1"
    i=i+1