Amazing Trick
시간 제한3초메모리 제한1024 MB
순열 a가 주어질 때, 고정점이 없는 두 순열 p, q가 a[p[q[i]]] = i를 만족하도록 찾거나 불가능함을 판정한다.
문제
Alice is a magician and she creates a new trick. She has cards with different numbers from to written on them. First, she asks an audience member to shuffle the deck and put cards in a row. Let's say the -th card from the left has the number on it.
Then Alice picks two permutations and . There is a restriction on and --- permutations can't have fixed points. Which means .
After permutations are chosen, Alice shuffles the cards according to them. Now the -th card from the left is the card . The trick is considered successful if -th card from the left has the number on it after the shuffles.
Help Alice pick the permutations and or say it is not possible for the specific starting permutation .
입력
The first line of the input contains the number of tests ().
Each test is described in two lines. The first line contains one integer --- the number of cards (). The second line contains integers --- the initial permutation of the cards (; ).
It is guaranteed that the sum of over all tests does not exceed .
출력
Print the answer for each test case in the same order the cases appear in the input.
For each test case, print "Impossible" in a single line, if no solution exists.
Otherwise, print "Possible" in the first line, and in the following two lines print permutations and .