310250: CF1805A. We Need the Zero

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. We Need the Zerotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

There is an array $a$ consisting of non-negative integers. You can choose an integer $x$ and denote $b_i=a_i \oplus x$ for all $1 \le i \le n$, where $\oplus$ denotes the bitwise XOR operation. Is it possible to choose such a number $x$ that the value of the expression $b_1 \oplus b_2 \oplus \ldots \oplus b_n$ equals $0$?

It can be shown that if a valid number $x$ exists, then there also exists $x$ such that ($0 \le x < 2^8$).

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.

The first line of the test case contains one integer $n$ ($1 \le n \le 10^3$) — the length of the array $a$.

The second line of the test case contains $n$ integers — array $a$ ($0 \le a_i < 2^8$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^3$.

Output

For each set test case, print the integer $x$ ($0 \le x < 2^8$) if it exists, or $-1$ otherwise.

ExampleInput
5
3
1 2 5
3
1 2 3
4
0 1 2 3
4
1 2 2 3
1
1
Output
6
0
3
-1
1
Note

In the first test case, after applying the operation with the number $6$ the array $b$ becomes $[7, 4, 3]$, $7 \oplus 4 \oplus 3 = 0$.

There are other answers in the third test case, such as the number $0$.

Input

题意翻译

给出一个由非负整数组成的序列 $a$,请你选择一个 $x$,使得 $ (a_1 \oplus x) \oplus (a_2 \oplus x) \oplus \dots \oplus (a_n \oplus x) = 0$。请求出 $x$,或者输出 $-1$ 表示不可能。

Output

题目大意:
给定一个由非负整数组成的数组a。可以选择一个整数x,并定义b_i = a_i XOR x对于所有1 ≤ i ≤ n,其中XOR表示按位异或操作。是否存在这样的数x,使得表达式b_1 XOR b_2 XOR ... XOR b_n的值为0?如果存在有效的数x,那么也存在x使得(0 ≤ x < 2^8)。

输入数据格式:
每个测试包含多个测试用例。第一行包含测试用例的数量t (1 ≤ t ≤ 1000)。接下来是测试用例的描述。
测试用例的第一行包含一个整数n (1 ≤ n ≤ 10^3) — 数组a的长度。
测试用例的第二行包含n个整数 — 数组a (0 ≤ a_i < 2^8)。
保证所有测试用例的n之和不超过10^3。

输出数据格式:
对于每个测试用例,如果存在整数x (0 ≤ x < 2^8),则输出x,否则输出-1。

示例:
输入
```
5
3
1 2 5
3
1 2 3
4
0 1 2 3
4
1 2 2 3
1
1
```
输出
```
6
0
3
-1
1
```
注意:
在第一个测试用例中,使用数字6进行操作后,数组b变为[7, 4, 3],7 XOR 4 XOR 3 = 0。
在第三个测试用例中,还有其他答案,例如数字0。题目大意: 给定一个由非负整数组成的数组a。可以选择一个整数x,并定义b_i = a_i XOR x对于所有1 ≤ i ≤ n,其中XOR表示按位异或操作。是否存在这样的数x,使得表达式b_1 XOR b_2 XOR ... XOR b_n的值为0?如果存在有效的数x,那么也存在x使得(0 ≤ x < 2^8)。 输入数据格式: 每个测试包含多个测试用例。第一行包含测试用例的数量t (1 ≤ t ≤ 1000)。接下来是测试用例的描述。 测试用例的第一行包含一个整数n (1 ≤ n ≤ 10^3) — 数组a的长度。 测试用例的第二行包含n个整数 — 数组a (0 ≤ a_i < 2^8)。 保证所有测试用例的n之和不超过10^3。 输出数据格式: 对于每个测试用例,如果存在整数x (0 ≤ x < 2^8),则输出x,否则输出-1。 示例: 输入 ``` 5 3 1 2 5 3 1 2 3 4 0 1 2 3 4 1 2 2 3 1 1 ``` 输出 ``` 6 0 3 -1 1 ``` 注意: 在第一个测试用例中,使用数字6进行操作后,数组b变为[7, 4, 3],7 XOR 4 XOR 3 = 0。 在第三个测试用例中,还有其他答案,例如数字0。

加入题单

算法标签: