感觉很像nim game可是实在是没懂啊。。。。Shashank is playing the NIM game with Sara. The NIM game rules are described below: . visit 1point3acres.com for more.
There are buckets. Each bucket contains or more ball(s). During each turn, a player selects a bucket and takes out or more ball(s). The last player to take out the last ball(s) wins the game.
Shashank makes a modification to the game because he is bored. For the first 50 moves, the game is played in the following manner:
- Shashank adds a bucket containing a non-zero number of balls.
- Sara adds a bucket containing a non-zero number of balls.
- Shashank selects a bucket and takes out or more balls.
- Sara selects a bucket and takes out or more balls.
After the first 50 moves, the usual rules of the NIM game are followed, and the addition of buckets does not take place. Shashank plays first. Shashank wants to know the minimum number of balls the first additional bucket should contain (which he is adding in the first turn of the game). If no such bucket exists, print −1.
Your task: Find the minimum number of balls Shashank should add to win the game.Input Format
The first line contains an integer , denoting the number of test cases.
The first line of each test case contains an integer , denoting the number of buckets.
The next line contains integers. The integer denotes the number of balls in the bucket.
Print the answer corresponding to each test case on separate lines.
, where is the integer.