#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1E4 + 10;
int inp[maxn], T, n;
void change(int l, int r)
{
for (int i = l, j = l + (r - l + 1) / 2; j <= r; j++, i++)
swap(inp[i], inp[j]);
}
int main(int argc, char const *argv[])
{
cin >> T;
while (T--)
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> inp[i];
std::vector<pii> ans;
for (int i = 1; i <= n; i++)
{
int pos = find(inp, inp + n, i + 1) - inp;
if (pos == i) continue;
if (i + 2 * (pos - i) - 1 <= n)
{
ans.push_back(make_pair(i, i + 2 * (pos - i) - 1));
change(i, i + 2 * (pos - i) - 1);
}
else
{
ans.push_back(make_pair(i + !((pos - i) & 1), pos));
change(i + !((pos - i) & 1), pos);
i--;
}
}
cout << ans.size() << endl;
for (auto it = ans.begin(); it != ans.end(); it++)
cout << it->first << " " << it->second << endl;
}
return 0;
}