#K40642. Unique Element Finder

    ID: 26688 Type: Default 1000ms 256MiB

Unique Element Finder

Unique Element Finder

You are given an array where every element appears exactly twice except for one unique element that appears only once. Your task is to find and output this unique element for each test case.

Using the properties of the XOR operation, recall that for any integer \( x \), \( x \oplus x = 0 \) and \( x \oplus 0 = x \). Therefore, if we XOR all the numbers in the array, the result will be the desired unique number since duplicates cancel each other out.

Formula: \( unique = arr[0] \oplus arr[1] \oplus \dots \oplus arr[n-1] \)

inputFormat

The input is read from stdin and has the following format:

  • The first line contains an integer \( T \) representing the number of test cases.
  • For each test case:
    • The first line contains an integer \( N \), denoting the number of elements in the array.
    • The second line contains \( N \) space-separated integers. It is guaranteed that every element, except one, appears exactly twice.

outputFormat

For each test case, output the unique element on a new line to stdout.

## sample
3
5
1 2 3 2 1
7
4 5 6 7 5 6 4
9
8 9 10 9 8 11 10 12 12
3

7 11

</p>