#include using namespace std; typedef long long ll; #define mem(x,v) memset(x,v,sizeof(x)) #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i) #define rep(i,a,b) for(register int i=(a);i=int(b);--i) #define gc getchar #define pc putchar #define fi first #define se second inline ll read(){ ll x=0,f=1;char c=gc(); for(;!isdigit(c);c=gc())if(c=='-')f=-1; for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48); return x*f; } inline void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');} inline void writeln(ll x){write(x);pc('\n');} inline void wri(ll x){write(x);pc(' ');} const int maxn = 1e5+233; vector s[maxn]; int ans[maxn],a[maxn],n; int l[maxn*2],r[maxn*2],tot; int L[maxn*2],R[maxn*2],v[maxn*2]; bool cmp(int x,int y){ return l[x] < l[y]; } void solve() { *ans = 0; tot = 0; n = read(); Rep(i,0,n) s[i].clear(); Rep(i,1,n){ a[i] = read(); ++tot; l[i] = r[i] = i; v[i]=L[i]=R[i]=0; s[a[i]].push_back(i); } Dep(i,n,1){ sort(s[i].begin(),s[i].end(),cmp); // printf("{%d}\n",i); if(s[i].size() % 2 == 1){ puts("Impossible"); return ; } // printf("[%d]~{%d}\n",i,s[i].size()); for(int x = s[i].size() - 1;x>=0;x -= 2){ if(r[s[i][x-1]] + 1 != l[s[i][x]]){ puts("Impossible"); return ; } ++tot; l[tot] = l[s[i][x-1]]; r[tot] = r[s[i][x]]; L[tot] = s[i][x-1]; R[tot] = s[i][x]; v[tot] = r[s[i][x-1]]; // printf("v[%d] = %d{%d %d}\n",tot,r[s[i][x-1]],L[tot],R[tot]); s[i-1].push_back(tot); // ans[++*ans] = s[i][x-1].se; } } if(s[0].size() != 1){ puts("Impossible"); return ; } puts("Possible"); priority_queue > Q; Q.push({-v[s[0][0]],s[0][0]}); while(!Q.empty()){ ans[++*ans] = -Q.top().fi; int x = Q.top().se; Q.pop(); if(L[x]>n) Q.push({-v[L[x]],L[x]}); if(R[x]>n) Q.push({-v[R[x]],R[x]}); } Rep(i,1,(*ans)-1) wri(ans[i]);writeln(ans[*ans]); // Dep(i,*ans,2)wri(ans[i]);writeln(ans[1]); } int main(){ int T = read(); while(T--){ solve(); } return 0; }