t=int(input())
while(t):
n=int(input())
L=input().split()
if(n==1):
print(-1)
else:
N,M=[],[]
for i in range(n):
L[i]=int(L[i])
N.append(0)
M.append(L[i])
M.sort()
x=[]
for i in range(n):
if(L[i]==M[i]):
N[i]=1
x.append(i)
if(x==[]):
for i in range(n):
print(M[i],end=" ")
print("")
else:
j=0
l=len(x)
while(x):
if(j>=l):
break
if(x[j]==n-1):
M[-1],M[-2]=M[-2],M[-1]
N[-1]=0
x=[]
else:
N[x[j]],N[x[j]+1]=0,0
M[x[j]],M[x[j]+1]=M[x[j]+1],M[x[j]]
if(j==l-1):
j+=1
else:
if(x[j+1]-x[j]==1):
j+=2
else:
j+=1
for i in M:
print(i,end=" ")
print("")
t-=1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef map<int,int> mii;
typedef pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<long long> vl;
typedef map<long long,long long> mll;
typedef pair<long long,long long> pl;
#define F first
#define pb push_back
#define S second
#define er erase
#define in insert
#define NOO cout<<"NO"<<nl;
#define YES cout<<"YES"<<nl;
#define NL cout<<endl;
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forin(i, n) for (int i = int(n-1); i >= 0; i--)
#define fast cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define test freopen("input.in","r",stdin); freopen("output.in","w",stdout)
const int N = 2e5 + 55;
// const ll mod = 1e9 + 7;
const ll mod = 998244353;
const char nl = '\n';
ll fact[N];
ll x,y,n,l,r,p,m,h,k,ans,ans2,opt,mid;
ll mx=INT_MIN,mn=INT_MAX,sm;
bool ok;
ll b[N],c[N],a[N];
void solve(){
cin>>n;
forn(i,n)cin>>a[i];
forn(i,n)b[i]=a[i];
sort(a,a+n);
if(n==1){
cout<<-1<<nl;
return;
}
forn(i,n-1) if(a[i]==b[i])swap(a[i],a[i+1]);
if(a[n-1]==b[n-1])swap(a[n-1],a[n-2]);
forn(i,n)cout<<a[i]<<" ";
cout<<nl;
}
int main()
{
fast;
#ifndef ONLINE_JUDGE
test;
#endif
int Tc=1;
cin >> Tc;
while(Tc--){
solve();
}
return 0;
}
1711D - Rain | 534A - Exam |
1472A - Cards for Friends | 315A - Sereja and Bottles |
1697C - awoo's Favorite Problem | 165A - Supercentral Point |
1493A - Anti-knapsack | 1493B - Planet Lapituletti |
747B - Mammoth's Genome Decoding | 1591C - Minimize Distance |
1182B - Plus from Picture | 1674B - Dictionary |
1426C - Increase and Copy | 520C - DNA Alignment |
767A - Snacktower | 1365A - Matrix Game |
714B - Filya and Homework | 31A - Worms Evolution |
1691A - Beat The Odds | 433B - Kuriyama Mirai's Stones |
892A - Greed | 32A - Reconnaissance |
1236D - Alice and the Doll | 1207B - Square Filling |
1676D - X-Sum | 1679A - AvtoBus |
1549A - Gregor and Cryptography | 918C - The Monster |
4B - Before an Exam | 545B - Equidistant String |