S'all good, man.
- James McGill, Better Call Saul
Saul Goodman is the best lawyer in the world. He believes that until proven guilty, every man, woman, and child in this country is innocent. However, one client of Saul is not so innocent.
Saul needs to build a solid story for his defense. There were n events, numbered from 1 to n. Saul needs to come up with an order q1β,q2β,β¦,qnβ, in which these events happened. His client, however, has a poor memory! If Saul tells him to remember permutation (q1β,q2β,β¦,qnβ) of events, he will remember permutation (pq1ββ,pq2ββ,β¦,pqnββ), where (p1β,p2β,β¦,pnβ) is some (fixed) permutation of integers from 1 to n.
Saul wants their permutations to be as consistent as possible: he wants to maximize the value of LCS((q1β,q2β,β¦,qnβ),(pq1ββ,pq2ββ,β¦,pqnββ)). Help him to find permutation (q1β,q2β,β¦,qnβ) which maximizes this value! If there are many such permutations, find any of them.
Here LCS(a,b) denotes the length of the longest common subsequence of sequences a and b. For example, LCS((1,3,4,2,5),(3,1,2,4,5))=3, and one of the common subsequences of length 3 is (1,2,5).
The first line contains a single integer t (1β€tβ€105) - the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer n (1β€nβ€106) - the length of the permutation.
The second line of each test case contains n integers p1β,p2β,β¦,pnβ (1β€piββ€n, all piβ are distinct) - the elements of the permutation.
It is guaranteed that the sum of n over all test cases does not exceed 106.
Output data
For each test case, output n integers q1β,q2β,β¦,qnβ (1β€qiββ€n, all qiβ are distinct) ~--- any permutation of integers from 1 to n, which maximizes the value of LCS((q1β,q2β,β¦,qnβ),(pq1ββ,pq2ββ,β¦,pqnββ)).
Example
stdin
2
4
1 2 3 4
6
6 5 4 3 2 1
stdout
1 2 3 4
1 6 2 5 3 4
Explanation
In the first test case, for q=(1,2,3,4), we have LCS((1,2,3,4),(p1β,p2β,p3β,p4β)) = LCS((1,2,3,4),(1,2,3,4))=4.
In the second test case, for q=(1,6,2,5,3,4), we have:
LCS((1,6,2,5,3,4),(p1β,p6β,p2β,p5β,p3β,p4β)) = LCS((1,6,2,5,3,4),(6,1,5,2,4,3)) = 3;oneofcommonsubsequencesoflength3is(1, 2, 3)$.