D. The AND, The OR, and The XOR
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In the lawless lands of the Binary West, three legendary figures govern the fate of numbers: The AND, The OR, and The XOR.

The AND is strict, seeking only the common ground among a group. The OR is greedy, claiming every bit of influence it can find. Finally, there is The XOR — the chaotic force that measures the tension between the strictness of The AND and the greed of The OR.

You are given a lineup of $$$n$$$ outlaws, where $$$a_i$$$ represents the bounty on the head of the $$$i$$$-th outlaw. You must choose a posse (subsequence) of at least two outlaws to minimize the tension.

Formally, for a chosen subsequence $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$ (where $$$1 \le i_1 \lt i_2 \lt \cdots \lt i_k \le n$$$), the tension score is defined as: $$$$$$(a_{i_1} \mathbin{\&} a_{i_2} \mathbin{\&} \cdots \mathbin{\&} a_{i_k}) \oplus (a_{i_1} \mathbin{|} a_{i_2} \mathbin{|} \cdots \mathbin{|} a_{i_k})$$$$$$ Here, $$$\&$$$, $$$|$$$, and $$$\oplus$$$ denote the bitwise AND, OR, and XOR operators, respectively.

Find the minimum possible tension score among all subsequences of size at least $$$2$$$.

Input

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) — the number of outlaws.

The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the bounties on the heads of the outlaws.

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

Output

For each test case, output a single integer — the minimum possible tension score among all subsequences of size at least $$$2$$$.

Example
Input
2
3
1 2 3
2
1 1
Output
1
0
Note

In the first test case, the possible subsequences with size at least $$$2$$$ and their scores are:

  • $$$(a_1, a_2)$$$: $$$(1 \mathbin{\&} 2) \oplus (1 \mathbin{|} 2) = 0 \oplus 3 = 3$$$
  • $$$(a_1, a_3)$$$: $$$(1 \mathbin{\&} 3) \oplus (1 \mathbin{|} 3) = 1 \oplus 3 = 2$$$
  • $$$(a_2, a_3)$$$: $$$(2 \mathbin{\&} 3) \oplus (2 \mathbin{|} 3) = 2 \oplus 3 = 1$$$
  • $$$(a_1, a_2, a_3)$$$: $$$(1 \mathbin{\&} 2 \mathbin{\&} 3) \oplus (1 \mathbin{|} 2 \mathbin{|} 3) = 0 \oplus 3 = 3$$$
So the minimum score is $$$1$$$.