显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 200010
inline ll read(){
ll x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
ll T,n,pd,a,b;
ll h[MAXN],mp[MAXN],p[MAXN];
void work(){
if(a>b)swap(a,b);
p[1]=a,p[n]=b;
ll l=1,r=n;
for(int i=1;i<n-1;i++){
if(p[l]>p[r])p[++l]=h[i];
else p[--r]=h[i];
}
}
int main(){
freopen("permutation.in","r",stdin);
freopen("permutation.out","w",stdout);
T=read();
while(T--){
n=read();
pd=0;
a=0,b=0;
for(int i=1;i<=n;i++)mp[i]=0;
for(int i=1;i<=n;i++)p[i]=0;
for(int i=1;i<n;i++){
h[i]=read();
mp[h[i]]++;
if(mp[h[i]]>1&&h[i]!=1)pd=1;
}
// ll a,b;
for(int i=1;i<=n;i++){
if(!mp[i]){
if(!a)a=i;
else if(!b)b=i;
else pd=1;
}
}
if(pd){
cout<<"-1\n";
continue;
}
if(b){
if(h[n-1]!=1){
cout<<"-1\n";
continue;
}else work();
// cout<<"fuck1\n";
// work();
}else{
// if(a==1)cout<<"-1\n";
if(a>1&&h[n-1]==1){
p[n]=a;
for(int i=n-1;i;i--)p[i]=h[n-i];
}else{
cout<<"-1\n";
continue;
}
}
for(int i=1;i<=n;i++)cout<<p[i]<<" ";
cout<<endl;
}
return 0;
}