#K85002. Find the Unique Element

    ID: 36544 Type: Default 1000ms 256MiB

Find the Unique Element

Find the Unique Element

You are given an array in which every element appears exactly twice except for one element which appears only once. Your task is to find and print this unique element for each test case. To solve this problem, you can take advantage of the properties of the bitwise XOR operation. Recall that for any integer \(a\), we have \(a \oplus a = 0\) and \(a \oplus 0 = a\). Thus, by XOR-ing all the numbers together, every pair cancels out, leaving the unique number remaining.

inputFormat

The input is given via standard input (stdin). The first line contains an integer (T) denoting the number of test cases. For each test case, the first line contains an integer (N) representing the number of elements in the array, followed by a line with (N) space-separated integers.

outputFormat

For each test case, output the unique element on a new line to standard output (stdout).## sample

4
5
1 2 3 2 1
7
4 1 2 1 2 4 6
5
10 10 20 20 30
7
7 7 3 3 9 9 8
3

6 30 8

</p>