2022-2023 ICPC, NERC, Northern Eurasia Onsite (Unrated, Online Mirror, ICPC Rules, Teams Preferred) |
---|

Finished |

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

constructive algorithms

graph matchings

math

probabilities

*1900

No tag edit access

The problem statement has recently been changed. View the changes.

×
A. Amazing Trick

time limit per test

3 secondsmemory limit per test

1024 megabytesinput

standard inputoutput

standard outputAlice is a magician and she creates a new trick. She has $$$n$$$ cards with different numbers from $$$1$$$ to $$$n$$$ written on them. First, she asks an audience member to shuffle the deck and put cards in a row. Let's say the $$$i$$$-th card from the left has the number $$$a_i$$$ on it.

Then Alice picks two permutations $$$p$$$ and $$$q$$$. There is a restriction on $$$p$$$ and $$$q$$$ — permutations can't have fixed points. Which means $$$\forall i: p_i \ne i\ and\ q_i \ne i$$$.

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

Help Alice pick the permutations $$$p$$$ and $$$q$$$ or say it is not possible for the specific starting permutation $$$a$$$.

Input

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

Each test is described in two lines. The first line contains one integer $$$n$$$ — the number of cards ($$$1 \leq n \leq 10^5$$$). The second line contains $$$n$$$ integers $$$a_i$$$ — the initial permutation of the cards ($$$1 \leq a_i \leq n$$$; $$$\forall i \neq j: a_i \neq a_j$$$).

It is guaranteed that the sum of $$$n$$$ over all tests does not exceed $$$10^5$$$.

Output

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 $$$p$$$ and $$$q$$$.

Example

Input

422 131 2 342 1 4 355 1 4 2 3

Output

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

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Feb/21/2024 12:29:52 (j3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|