14436 - Exchange Department   

Description

In a company, there are N employees and M departments, with employees' IDs numbered from 1 to N. Initially, employee i is assigned to department Ai.

Recently, the company has introduced several new product development plans, which have resulted in a series of personnel transfers. Specifically, for each transfer, a pair xi and yi is provided, indicating that the employee with ID xi and the employee with ID yi will swap departments.

These transfers happen in a specific order, where if i < j, the employees xi and yi swap departments first, followed by employees xj  and yj.

The company’s boss would like to know which employees are in department Q after T transfers. Can you design a system that can provide this information?

Input

The first line of input contains three positive integers N, M, and T, representing the number of employees, departments, and personnel transfers, respectively.

The second line contains N integers A1, A2, ..., A, where Ai represents the initial department of the i-th employee.

The next T lines (from the 3-rd line to the (T + 2)-th line) each contain two integers, xi and yi, indicating that employee xi and employee yi swapped departments during the corresponding personnel transfer.

The (T + 3)-th line contains a positive integer Q, representing the department the company's boss is inquiring about. Specifically, it asks which employees are currently assigned to department Q.

 

Constraints

  • 1 ≤ N,T ≤ 105
  • 1 ≤ M ≤ min(N,100)
  • 1 ≤ Q ≤ M
  • for all i in [1,N], 1 ≤ Ai ≤ M
  • for all i in [1,N], 1 ≤ xi,yi N ; xi yi

Subtasks

  • Testcases 1~3: 1 ≤ N,T ≤ 500
  • Testcases 4~5: N = 100; Ai = i
  • Testcases 6~7: T = 1
  • Testcases 8~10: No additional restrictions.

Output

Please output one line containing all employee IDs that are currently assigned to department Q after T personnel transfers, in increasing order.

Employee IDs should be separated by a space, and please ensure that there is no space after the last employee ID. 

Please print "\n" at the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss