#K62747. Final Holder Determination

    ID: 31600 Type: Default 1000ms 256MiB

Final Holder Determination

Final Holder Determination

You are given T test cases. In each test case, a sequence of instructions is provided with each instruction in the form of a pair of integers \(A\) and \(B\), meaning that the ball is passed from person \(A\) to person \(B\). The ball initially starts with the person indicated by the first instruction's \(A\) value. For every subsequent instruction in the same test case, the ball is passed to the person indicated by its \(B\) value.

Your task is to determine the final holder of the ball for each test case. Mathematically, if a test case has \(N\) instructions \((A_1, B_1), (A_2, B_2), \dots, (A_N, B_N)\), then the final holder is given by:

[ holder = B_N ]

Note: If the number of test cases is zero, the program should produce no output.

inputFormat

The input is read from stdin and is formatted as follows:

  • The first line contains a single integer \(T\) representing the number of test cases.
  • For each test case:
    • The first line contains an integer \(N\) indicating the number of instructions.
    • The next \(N\) lines each contain two space-separated integers \(A\) and \(B\), representing an instruction where the ball is passed from \(A\) to \(B\).

outputFormat

For each test case, output a single integer on a new line representing the final holder of the ball. The output should be written to stdout.

## sample
1
3
1 2
2 3
3 4
4

</p>