#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define F first
#define S second
using namespace std;
int n;
int add[101], a[101];
void smartSolve() {
vector<pair<int,int>> ans;
for (int i=1;i<n-2;i++) {
if (add[i]==i) continue;
if (add[i]==i+1) {
ans.push_back({i+1,n});
swap(a[i+1],a[n]);
swap(add[a[n]],add[a[i+1]]);
ans.push_back({i,n});
swap(a[i],a[n]);
swap(add[a[i]],add[a[n]]);
} else {
ans.push_back({i,add[i]});
swap(a[i],a[add[i]]);
swap(add[i],add[a[add[i]]]);
}
if (add[i]!=i) cerr<<"???"<<endl;
}
if (a[n-2]==n-2 && a[n-1]==n) {
ans.push_back({1,n});
ans.push_back({1,n-1});
ans.push_back({1,n});
}
if (a[n-2]==n-1 && a[n-1]==n-2) {
ans.push_back({n-2,n});
ans.push_back({1,n});
ans.push_back({1,n-1});
ans.push_back({1,n});
ans.push_back({n-2,n});
}
if (a[n-2]==n-1 && a[n-1]==n) {
ans.push_back({n-2,n});
ans.push_back({1,n});
ans.push_back({1,n-1});
ans.push_back({1,n});
}
if (a[n-2]==n && a[n-1]==n-2) {
ans.push_back({1,n});
ans.push_back({1,n-1});
ans.push_back({1,n});
ans.push_back({n-2,n});
}
if (a[n-2]==n && a[n-1]==n-1) {
ans.push_back({n-2,n});
}
cout<<ans.size()<<"\n";
for (auto x : ans) cout<<x.F<<" "<<x.S<<"\n";
}
void solve() {
if (n==1) {
cout<<"0\n";
return;
}
if (n==2) {
if (a[1]==1) cout<<"0\n";
else cout<<"-1\n";
return;
}
if (n==3) {
if (a[2]!=2) {
cout<<"-1\n";
return;
}
if (a[1]==1) cout<<"0\n";
else cout<<"1\n1 3\n";
return;
}
smartSolve();
}
void readTst() {
cin>>n;
for (int i=1;i<=n;i++) {
cin>>a[i];
add[a[i]]=i;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int tst;
cin>>tst;
for (int t=0;t<tst;t++) {
readTst();
solve();
}
}