## IITKWPCI - Find Lexicographically Smallest Permutation

no tags

You are given n numbers a1, a2, ... an. You have to permute the numbers in such a way that resulting permutation should be lexicographically smallest . But there is a problem, you can not swap every pair of numbers. You can only swap the position i and j if they are good position. You will be given m pairs of i and j's which will denote good positions.

So complying to restrictions posed here, find the lexicographically smallest permutation of a1, a2 ... an.

Definition:  (a1, a2 ... an) is lexicographically smaller than (b1, b2 ... bn) if first index i where ai and bi differs, ai < bi satisfies.

eg. (1, 2, 3, 4) is smaller than (2, 1, 3, 4)

### Input

T : number of test cases (T <= 10)

Next Line will contain n and m. (1 <= n <= 10^3 and 0 <= m <= min (n * (n - 1) / 2, 10^5).

Next Line will contains a1, a2, ... an. (a[i] >= 1 && a[i] <=10^6)

For next m lines, each line will contain i, j separated by space which will denote that you can swap ai and aj.

### Output

For each test case, output n numbers representing the permutation of a1, a2 ... an according to problem statement.

### Example

```Input:
23 13 2 12 34 22 4 3 11 33 4
Output:
3 1 21 4 2 3```