NOI Contest Archive

Archive / 2022 / Final Round — Day 2

New Suvin’s Magic Tricks

Medium · National Olympiad in Informatics Sri Lanka 2022 - Day 2

Suvin is back with a group of children and he is going to play a game. Each child has a number card in his/her pocket that denotes the lucky number of that child.

Those children will not come to play unless their lucky scores are the same. The lucky score of a child is calculated by counting the number of \(1-bits\) in the binary representation of their respective lucky number.

However, since it is unlikely for all the children to have the same lucky score, Suvin made an arrangement with the children, where he will name a magic number \(X\), which will be used to change all the lucky numbers of children, by computing the XOR between the original lucky number and \(X\).

Now, Suvin has to find a magic number such that when the new lucky numbers are computed, the lucky scores of children will become equal.

You have to help Suvin with this task. Find a magic number that is less than \(2^{30}\), or let him know that no such number exists.

Input Format

The first line contains the number of test cases \(T\).

Then for each test case \(T_i\):

Output Format

For each test case \(T_i\):

Constraints

Limits

Sample Input 0

2
2
7 2
3
1 2 3

Sample Output 0

1
-1