#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 111;
bool h[N];
typedef pair<int, int> pii;
vector<pii> ans;
vector<int> v;
int n;
bool sol;
void solveBrute(int k, int d) {
if(sol) return;
if(d >= 6) return;
bool thisSol = true;
for(int i = 1; i <= k; ++i) {
if(v[i-1] != i) {
thisSol = false;
break;
}
}
if(thisSol) {
sol = true;
return;
}
for(int i = 0; i < k; ++i) {
for(int j = i+2; j < k; ++j) {
ans.push_back({i+1, j+1});
swap(v[i], v[j]);
solveBrute(k, d+1);
if(sol) {
break;
}
swap(v[i], v[j]);
ans.pop_back();
}
if(sol) break;
}
}
void solve() {
if(n == 1) {
cout << "0\n";
return;
}
if(n == 2) {
if(v[0] == 1) {
cout << "0\n";
} else {
cout << "-1\n";
}
return;
}
if(n == 3) {
if(v[1] != 2) {
cout << "-1\n";
} else {
if(v[0] == 1) {
cout << "0\n";
} else {
cout << "1\n";
cout << "1 3\n";
}
}
return;
}
for(int i = n; i >= 1; --i) {
int j = -1;
for(int k = 0; k < n; ++k) {
if(v[k] == i) {
j = k;
break;
}
}
if(j == i-1) continue;
if(j < i-2) {
ans.push_back({j+1, i});
swap(v[j], v[i-1]);
continue;
}
if(j >= 3) {
ans.push_back({j+1, 1});
swap(v[j], v[0]);
ans.push_back({i, 1});
swap(v[i-1], v[0]);
continue;
}
solveBrute(4, 0);
}
cout << ans.size() << "\n";
for(int i = 0; i < ans.size(); ++i) {
cout << ans[i].first << " " << ans[i].second << "\n";
}
}
int main() {
iostream::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for(int q = 1; q <= t; ++q) {
cin >> n;
for(int i = 1; i <= n; ++i) {
int a;
cin >> a;
v.push_back(a);
}
solve();
v.clear();
}
}