Consider ten variables that are indexed by integers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
The ten variables are divided into two groups, say, Group A: 1 3 5 7 9 and Group B: 0 2 4 6 8.
Given a sequence of SWAP commands, your program has to perform the exchange between the specified members.
For example, if the SWAP command is 2 3, then Group A becomes 1 2 5 7 9 and Group B is now 0 3 4 6 8.
If the next SWAP command is 5 4, then Group A becomes 1 2 4 7 9 and Group B becomes 0 3 5 6 8.
If the next SWAP command is 7 9, then nothing changes, Group A is still 1 2 4 7 9 and Broup B is 0 3 5 6 8.
The task is to print the final members of Group A.
The first line of input is an integer K indicating the number of variables in Group A. (0 < K < 10)
The second line of input contains the variables that belong to Group A. The variables that are not in Group A are all in Group B.
The third line of input is an integer N indicating the number of SWAP operations. (0 < N < 100)
The next N lines specify the SWAP operations for exchaning group members.
Each SWAP operation is represented by a pair of integers indicating the indexes of the two variables to be exchanged.
The output contains only one line listing the variables that belong to Group A.
The variables are listed in ascending order with respect to their indexes, with a whitespace in between, and NO newline character at the end.