#K86157. Remote Swap Process

    ID: 36802 Type: Default 1000ms 256MiB

Remote Swap Process

Remote Swap Process

You are given an array of n integers and m swap operations. In each operation, you will be given two indices x and y (1-indexed), and you must swap the values at these positions.

Your task is to simulate all swap operations for each test case and output the final state of the array.

The process for each test case is as follows:

  • Read two integers \(n\) and \(m\), where \(n\) is the size of the array and \(m\) is the number of swap operations.
  • Read \(n\) integers which form the array.
  • For each of the \(m\) operations, read two integers \(x\) and \(y\) and swap the elements at positions \(x\) and \(y\) (indices are 1-indexed).
  • Output the final state of the array as space-separated integers.

Note: All indices are 1-indexed. The swapping should be performed sequentially in the order given.

inputFormat

The first line of input contains an integer T denoting the number of test cases.

For each test case:

  • The first line contains two integers n and m, where \(1 \leq n \leq 10^5\) and \(0 \leq m \leq 10^5\).
  • The second line contains n space-separated integers representing the initial state of the array.
  • The following m lines each contain two integers x and y (\(1 \leq x, y \leq n\)) representing a swap operation.

Input is read from standard input (stdin).

outputFormat

For each test case, output one line containing the final state of the array as n space-separated integers after performing all swap operations.

Output should be written to standard output (stdout).

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

1 2 4 3

</p>