아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Amazing Trick

시간 제한3초메모리 제한1024 MB

요약
순열 a가 주어질 때, 고정점이 없는 두 순열 p, q가 a[p[q[i]]] = i를 만족하도록 찾거나 불가능함을 판정한다.
난이도

보통10점 중 6점

유형
조합론, 구현, 수학
정답자
아직 제출이 없습니다

문제

Alice is a magician and she creates a new trick. She has nn cards with different numbers from 11 to nn written on them. First, she asks an audience member to shuffle the deck and put cards in a row. Let's say the ii-th card from the left has the number a_ia\_i on it.

Then Alice picks two permutations pp and qq. There is a restriction on pp and qq --- permutations can't have fixed points. Which means ∀i:p_i≠i and q_i≠i\forall i: p\_i \ne i\ \text{and}\ q\_i \ne i.

After permutations are chosen, Alice shuffles the cards according to them. Now the ii-th card from the left is the card a\[p\[q\[i]]a\[p\[q\[i]]. The trick is considered successful if ii-th card from the left has the number ii on it after the shuffles.

Help Alice pick the permutations pp and qq or say it is not possible for the specific starting permutation aa.

입력

The first line of the input contains the number of tests tt (1≤t≤1051 \leq t \leq 10^5).

Each test is described in two lines. The first line contains one integer nn --- the number of cards (1≤n≤1051 \leq n \leq 10^5). The second line contains nn integers a_ia\_i --- the initial permutation of the cards (1≤a_i≤n1 \leq a\_i \leq n; ∀i≠j:a_i≠a_j\forall i \neq j: a\_i \neq a\_j).

It is guaranteed that the sum of nn over all tests does not exceed 10510^5.

출력

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 pp and qq.

예제1

  1. 예제 1

    입력
    4
    2
    2 1
    3
    1 2 3
    4
    2 1 4 3
    5
    5 1 4 2 3
    
    예상 출력
    Impossible
    Possible
    3 1 2
    2 3 1
    Possible
    3 4 2 1
    3 4 2 1
    Possible
    4 1 2 5 3
    3 1 4 5 2