11321 - CS Simple 004   

Description

Consider nine variables that are indexed by integers 1, 2, 3, 4, 5, 6, 7, 8, 9.
The nine variables are divided into two groups, say, Group A: 1 3 5 7 9 and Group B: 2 4 6 8.
Given a sequence of SWAP commands, your program has to perform the exchange between the specified members.


[Example]

For example, if the SWAP command is 2 3, then Group A becomes 1 2 5 7 9 and Group B is now 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 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 3 5 6 8.

The task is to print the final members of  Group A.

 

[Hint]

Similar to the problem of finding equivalence relation. Variables that belong to the same group are considered equivalent.

 

Input

The first line of input is an integer K indicating the number of variables in Group A. (0 < K < 9)
The variables that are not in Group A are all in Gropu B.

The second line of input contains the K 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.

Output

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.

Sample Input  Download

Sample Output  Download

Tags




Discuss