#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define x first
#define y second
bool solve(int n, vector<int>& arr, vector<pii>& ans) {
vector<int> pos(n);
for (int i=0; i<n; i++)
pos[arr[i]] = i;
auto mv = [&](int i, int j) {
if (abs(i-j)<=1 || arr[i]==i) return;
swap(arr[i], arr[j]);
swap(pos[arr[i]], pos[arr[j]]);
ans.emplace_back(i, j);
};
for (int j=0; j<n; j++) {
int x = (j+1)%n;
mv(pos[x], x);
mv(pos[x], 0);
mv(pos[x], x);
mv(pos[x], n-1);
mv(pos[x], x);
if (arr[x] != x)
return false;
}
return true;
}
signed main() {
ios::sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> arr(n);
for (int i=0; i<n; i++) {
cin >> arr[i];
arr[i]--;
}
vector<pii> ans;
if (!solve(n, arr, ans))
cout << "-1\n";
else {
cout << ans.size() << '\n';
for (auto p : ans)
cout << p.x+1 << ' ' << p.y+1 << '\n';
}
}
}