#C2644. Find the Unique Integer

    ID: 45983 Type: Default 1000ms 256MiB

Find the Unique Integer

Find the Unique Integer

You are given a list of integers in which every integer appears exactly twice except for one unique integer that appears only once. Your task is to find and print this unique integer.

The problem is based on the properties of the bitwise XOR operation, which has the useful property that a ⊕ a = 0 and a ⊕ 0 = a. This allows us to effectively cancel out paired numbers and isolate the unique number.

Input Format (in stdin):

  • The first line contains a single 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 list.
    • The second line contains \(n\) space-separated integers. It is guaranteed that every integer appears exactly twice except for one integer that appears exactly once.

Output Format (in stdout):

  • For each test case, output the unique integer on a new line.

Example:

Input:
1
7
2 3 2 4 4 3 5

Output: 5

</p>

inputFormat

The first line contains a single integer T — the number of test cases. Each test case consists of two lines. The first line contains an integer n, the number of elements, and the second line contains n space-separated integers. It is guaranteed that each integer appears exactly twice except for one unique integer.

outputFormat

For each test case, output the unique integer on a new line.## sample

1
7
2 3 2 4 4 3 5
5

</p>