Logical Ops

0

0 votes
Problem

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
Time Limit: 1
Memory Limit: 8
Source Limit:
Explanation

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

Test Case #2 One And Equation is possible as 3 & 9 & 5 = 1

Editor Image

?