Loading...
Cheaters
Time: 1 s
Memory: 125 MB
The problem solvers of Programmerforces University arranged a Contest for Junior programmers. Unfortunately, one student leaked the solution and shared it with one other student. That student later shared the solution with another student and so on.  As a result, the problem solver community of Programmerforces University decided to ban them from all upcoming contests. The problem solvers community asked you to write a program that can find the cheater's id in order.

NB: Only one student leaked the solution, and every cheater passed the solution to at most one student and no cheater got the solution from multiple cheaters.

You are given an array \(a\). \(a_i\) represents -  \(i_{th}\)  cheater got the solution from the student with id \(a_i\). You have to print the cheater's id in order. (First who leaked the solution and how it was passed all the way.)
Input
First Line contains a single integer \(t\) \((1 \leq t \leq 20)\) which is number of test cases. Second line contains a single integer n \((1 \leq n \leq 50)\) is the number of students who cheated in the contest and the third line contains n integers   \(a_i , a_{i+1} , a_{i+2}........ a_n\)\((1 \leq a_i \leq n)\) which represents the id number of the n students.
Output
Print ID numbers (in order) of n students.

You can assume that there will be no cycle and a solution will always exist.
Examples
Input
Output
3
3
2 3 3
5
5 2 2 3 4
4
2 4 1 4
3 2 1
2 3 4 5 1
4 2 1 3
Notes
In every test case there will be an integer \(a_i\) where \(a_i = i\). this means student with id  \(a_i\) was the first who leaked the solution.

In the first case, the output is - 3 2 1 which means student with id 3 leaked the solution and passed it to the student with id 2. After getting the soluion student with id 2 passed the solution to the student with id 1.
 
Problem Info
Problem ID 40
Time Limit 1000 ms
Memory Limit 128000 KB
Moderators BeNew , AmirHamza , Swakshar , GoodFella
Statistics
Submit
You need to Login or Registration for submit your solution