#include using namespace std; const int maxn = 3e5, inf = 1e9; int t, n, a[maxn + 10], ndcnt; int stk[maxn + 10], scnt, id[maxn + 10]; int lc[maxn * 2 + 10], rc[maxn * 2 + 10]; int ans[maxn * 2 + 10], acnt, sz[maxn * 2 + 10]; void dfs(int p) { sz[p] = 1; if (p <= n) return; else { dfs(lc[p]); dfs(rc[p]); sz[p] = sz[lc[p]] + sz[rc[p]]; } } void dfs2(int p, int ls) { if (p <= n) { assert(p == ls); return; } else { ans[++acnt] = ls + sz[lc[p]] - 1; dfs2(lc[p], ls); dfs2(rc[p], ls + sz[lc[p]]); } } int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); scnt = 0; ndcnt = n; for (int i = 1; i <= n; ++i) { stk[++scnt] = a[i]; id[scnt] = i; while (scnt >= 2 && stk[scnt] == stk[scnt - 1]) { ++ndcnt; lc[ndcnt] = id[scnt - 1]; rc[ndcnt] = id[scnt]; --scnt; --stk[scnt]; id[scnt] = ndcnt; } } if (scnt > 1 || stk[scnt] != 0) { printf("Impossible\n"); continue; } acnt = 0; dfs(id[1]); dfs2(id[1], 1); printf("Possible\n"); assert(acnt == n - 1); for (int i = 1; i <= acnt; ++i) printf("%d%c", ans[i], " \n"[i == acnt]); } }