

There are three numbers, say 8, 5 and 10.
8 can be written as 1 0 0 0 .
5 can be written as 0 1 0 1.
10 can be written as 1 0 1 0.
positions of the bits as i j k l.
So we can see majority bit at ith position are set bits so ith bit will be 1. Similarly for positions of j, k and l are set as 0 0 0 respectively.
So the number generated is 1 0 0 0 i.e. 8.
The first line contains a single integer ‘T’ representing the number of test cases.
Then ‘T’ test cases follows:
First line of each test case contains an integer ‘N’ representing the size of the input array ‘arr’.
Next line contains ‘N’ space separated integers denoting the elements in the ‘arr’.
Output of each test case an integer as per the condition.
1 <= T <= 5
1 <= N <= 10 ^ 3
1 <= arr[i] <= 5 * (10 ^ 3)
Time Limit: 1sec
The idea is to count the number of set and unset bits for every integer of ‘arr’ and for every ‘ith’ index of all positions in the maximum bit.