#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
for (int Ti = 0; Ti < T; ++Ti) {
int n;
cin >> n;
int t[n];
for (int i = 0; i < n; ++i) cin >> t[i];
if (n == 2) {
cout << (t[0] == 1 ? 0 : -1) << endl;
continue;
}
if (n == 3) {
if (t[1] != 2) {
cout << -1 << endl;
} else if (t[0] != 1) {
cout << "1\n1 3\n";
} else {
cout << "0\n";
}
continue;
}
vector<pair<int, int>> res;
for (int a = 0; a < n; ++a) {
if (t[a] == a+1) continue;
int b;
for (int j = a+1; j < n; ++j) {
if (t[j] == a+1) {
b = j;
break;
}
}
swap(t[a], t[b]);
if (a > b) swap(a, b);
if (b == a+1) {
if (a > 1) {
res.emplace_back(0, b);
res.emplace_back(0, a);
res.emplace_back(0, b);
} else if (b < n-2) {
res.emplace_back(b, n-1);
res.emplace_back(a, n-1);
res.emplace_back(b, n-1);
} else {
res.emplace_back(1, 3);
res.emplace_back(0, 2);
res.emplace_back(0, 3);
res.emplace_back(1, 3);
res.emplace_back(0, 2);
}
} else {
res.emplace_back(a, b);
}
}
cout << res.size() << endl;
for (auto [a, b] : res) cout << a+1 << " " << b+1 << endl;
}
}