Pawan has a finite number of friends, each friend has a unique non-negative number associated with him. (0, 1, 2..)
Pawan plans to host a party and has to send notifications to his friends.
A friend attends the party if he receives at least 1 notification from Pawan.
To send notifications, Pawan buys data plans
Pawan can send notifications using data plan X in the following way:
Let's say Data plan X costs Y.
Then a friend associated with the number i will receive a notification if and only if the ith bit in Y is set.
Now Pawan wonders if he can cut costs. Let him know the maximum cost that he can cut by removing at most 1 data plan and still being able to invite all the friends he could invite earlier
Input
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤100) — the number of test cases. Description of the test cases follows.
The first line of each test case contains one integer N - the number of data plans
The second line of each test case contains N integers a1,a2,…,an — the cost of data plans array.
It is guaranteed that the sum of N over all test cases does not exceed 105
Output
For each test case, print a line containing a single integer – the maximum possible money that Pawan can save (print 0 if no data plan can be removed)
Constraints
1<=T<=100
1<=N<=105
0<=ai<=109
In the first case, the data plans cost 10rs and 5rs, With the first data plan(10rs) we can invite 1st and the 3rd friend because in the binary representation of 10 (1010) the first and the third bit are set, and with the second data plan (5rs), we can invite 0th and the 2nd friend because in the binary representation of 5(101), the 0th and the 2nd bit is set
Now with all the data plans, we could invite the 0th, 1st,2nd, and 3rd friends, but if we remove any data plans, there will be a friend who will be left. Therefore the answer is 0rs
In the second case, the cost of all the data plans is the same, so if we remove any one data plan, we will still be able to invite all the friends we invited before. Therefore the answer is 9rs