Consider a complete binary tree with N leaves. Every node of the tree stores a positive value. The tree has been built in such a way that every internal node of the tree has a value that is xor of the values of it's two children.
You are given N integers, denoting the values of the N leaves. Find and print the value at the root node.
It can be proven that this value can be uniquely determined.
Input Format
The first line will consist of an integer T, denoting the number of test cases.
Each of the T test cases that follow, will consist of two lines.
The first line for each test case will consist of the integer N.
The second line for each test case will consist of N space separated integers \(A_1, A_2, ... , A_N\) , where \(A_i\) denotes the value in the \(i^{th}\) leaf.
Output Format
For each of the T test cases, print the value at the root node in a new line.
Constraints
\( 1 \le T \le 100 \)
\( 2 \le N \le 1000 \)
\( 1 \le A_i \le 10^9 \)
In the first case, for any complete binary tree that you can create with 3 leaves having the given values, the value at the root will be 2.
For the second case, you can see a sample Complete Binary Tree with the values in the leaves as given in the input.
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
Login to unlock the editorial
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