A XOR operation
88% Success6158 Attempts20 Points2s Time Limit256MB Memory1024 KB Max Code

You are given a set \(S\) of distinct positive integers of size \(n\) (\(n\) is always even). Print the minimum positive integer \(k\) that is greater than 0 such that after replacing each element \(e\) of the set \(S\) with \(e⊕k\), set \(S\) remains the same.

Print -1 if there is no such \(k\).

Note: It is guaranteed that \(\frac{n}{2}\) is odd.

Input format

  • The first line contains a single integer \(t\ (1\le t \le 100)\) denoting the number of test cases.
  • The first line of each test case contains a single integer \(n\ (2 \le n \le 1e5)\) denoting the number of elements in the set.
  • The second line of each test case contains \(n\) integers \(e\ (1 \le e \le 1e9)\).

Output format

Print \(t\) lines each containing a single line that contains \(k\).

Examples
Input
1
6
5 6 9 10 13 14
Output
3
Explanation

By performing the XOR of k with each element we get the given set S

5⊕3=6

6⊕3=5

13⊕3=14

14⊕3=13

9⊕3=10

10⊕3=9

S' = {6,5,14,13,10,9} which is same as S={5,6,13,14,9,10}

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading Editor...
Results