代码:
#include <bits/stdc++.h>
using namespace std;
int a[100010], pos[100010], p[100010], q[100010];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
a[x] = i;
pos[a[x]] = x;
}
int cnt = 0;
for (int i = 1; i <= n; i++)
{
p[i] = (i + cnt) % n + 1;
q[pos[p[i]]] = i;
if (q[pos[p[i]]] == pos[p[i]]) cnt++;
}
if (cnt >= n - 1)
{
cout << "Impossible" << endl;
continue;
}
for (int i = 1; i <= n; i++)
{
p[i] = (i + cnt) % n + 1;
q[pos[p[i]]] = i;
}
cout << "Possible" << endl;
for (int i = 1; i <= n; i++) cout << p[i] << " ";
cout << endl;
for (int i = 1; i <= n; i++) cout << q[i] << " ";
cout << endl;
}
return 0;
}