没啥思路,看到题解,先处理最大值,发现非常的nice
// Problem: C. Polycarp Recovers the Permutation
// Contest: Codeforces - Codeforces Round 756 (Div. 3)
// URL: https://codeforces.com/problemset/problem/1611/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N = 2e5+10;
int a[N];
void solve()
{
int n;cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
if(a[1]!=n&&a[n]!=n){
cout<<-1<<"\n";
return;
}
for(int i=n;i>=1;--i)cout<<a[i]<<" ";
cout<<"\n";
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int _;cin>>_;
while(_--)solve();
return 0;
}