FUN OF XOR SUM
Time: 1 s
Memory: 250 MB
Memory: 250 MB
You are given an array a consisting of n integers. Your task is to calculate the XOR sum of the "beauty" of all possible subsequences of a.
The beauty of a subsequence is:
Note that, XOR SUM of an array means the Bitwise Exclusive OR of all elements.
The beauty of a subsequence is:
- If a subsequence contains fewer than three unique elements, its beauty is 0.
- else its beauty is the 2nd minimum element.
Note that, XOR SUM of an array means the Bitwise Exclusive OR of all elements.
Input
The first line contains the number of test cases \(t,  (1 ⤠t ⤠10^4)\). The description of the test cases follows.The first line of each test cases contain an integer \(n, (1 ⤠n ⤠2 \times 10^5)\) denoting the size of the array.
The second line contains n integers of array \( a_1,a_2,a_3...a_n (1 \le a_i \le 10^9)\).
Additional constraint:
The sum of n over all test cases does not exceed \(2 \times 10^5\).
Output
For each test case, print a single integer representing the XOR sum of the beauty of all subsequences.
Examples
| Input | Output |
|---|---|
|
5
1 2 3 1 2 1 4 1 2 3 1 5 5 7 11 1 8 6 1784732 1022362 59929 1966683 1717245 804042 |
0
0 2 13 1472311 |
Notes
In the first testcase, Only one subsequence {2} exist containing fewer than three unique elements. So the beauty is 0.So the answer = 0.In the third testcase,the beauty of all possible subsequences as follows:
{1} = 0,{2} = 0,{3} = 0,{1} = 0,{1,2} = 0, {1,3} = 0, {1,1} = 0, {2,3} = 0, {2,1} = 0, {3, 1} = 0,{1,2,3} = 2, {1,2,1} = 0, {1,3,1} = 0, {2,3,1} = 2,{1,2,3,1} = 2.
So the answer = \(0 \oplus 0 \oplus 0 \oplus 0 \oplus 0 \oplus 0 \oplus 0 \oplus 0 \oplus 0 \oplus 0 \oplus 2 \oplus 0 \oplus 0 \oplus 2 \oplus 2 = 2\)