#include #include #include using namespace std; struct node{ int l,r,d; } s[220000]; struct so{ int i,l,d; }; bool operator < (so x1,so x2){ if(x1.d==x2.d)return x1.l>x2.l; return x1.dq; int f; void clr(){ int i; for(i=1;i<=tot;i++)ls[i]=rs[i]=0; for(i=1;i<=n;i++)ans[i]=0; tot=0; id=0; while(q.size())q.pop(); f=0; } void addedge(int u,int v, int kind){ //printf("ad%d %d %d\n",u,v,kind); if(kind==0)ls[u]=v; else rs[u]=v; } void dfs(int i, int d){ //printf("%d %d\n",i,d); if(s[i].l==s[i].r){ if(d!=s[i].d)f=0; return; } ans[++id]=s[ls[i]].r; dfs(ls[i],d+1); dfs(rs[i],d+1); } void xx(){ int i; so t,y; scanf("%d",&n); clr(); for(i=1;i<=n;i++){ scanf("%d",&a[i]); s[i].l=s[i].r=i; s[i].d=a[i]; t.i=i;t.l=i;t.d=a[i]; q.push(t); } tot = n; while(q.size()>1){ t=q.top();q.pop(); if(q.top().d!=t.d) { printf("Impossible\n"); return; } y=q.top();q.pop(); if(s[t.i].r+1!=y.l) { printf("Impossible\n"); return; } tot++; s[tot].l=t.l;s[tot].r=s[y.i].r;s[tot].d=t.d-1; addedge(tot,t.i,0); addedge(tot,y.i,1); t.i=tot;t.l=s[tot].l;t.d=s[tot].d; q.push(t); } f=1; dfs(tot,0); if(!f){ printf("Impossible\n"); return; } printf("Possible\n"); for(i=1;i<=n-1;i++)printf("%d%c",ans[i],i==n-1?'\n':' '); } int main () { int t; scanf("%d",&t); while(t--)xx(); return 0; }