#K74182. Find the Unique Element in Triplet Arrays

    ID: 34141 Type: Default 1000ms 256MiB

Find the Unique Element in Triplet Arrays

Find the Unique Element in Triplet Arrays

Given an array where every element appears exactly three times except one, your task is to determine the unique element that appears only once. This problem can be solved efficiently using bitwise operations. In particular, you can use the following bitwise formulas to cancel out elements appearing three times:

( ones = (ones \oplus num) \land \sim twos )
( twos = (twos \oplus num) \land \sim ones )

where (\oplus) denotes the bitwise XOR operation, (\land) denotes the bitwise AND, and (\sim) denotes the bitwise NOT operation.

inputFormat

The input begins with an integer T, the number of test cases. For each test case, the first line contains an integer n, representing the number of integers in the array. The next line contains n space-separated integers.

outputFormat

For each test case, output a single line containing the unique integer that appears exactly once.## sample

1
10
2 2 3 2 5 5 5 6 6 6
3

</p>