#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define SF(a) scanf("%d", &a) #define PF(a) printf("%d\n", a) #define SFF(a, b) scanf("%d%d", &a, &b) #define SFFF(a, b, c) scanf("%d%d%d", &a, &b, &c) #define SFFFF(a, b, c, d) scanf("%d%d%d%d", &a, &b, &c, &d) #define CLEAR(a, b) memset(a, b, sizeof(a)) #define IN() freopen("in.txt", "r", stdin) #define OUT() freopen("out.txt", "w", stdout) #define FOR(i, a, b) for(int i = a; i < b; ++i) #define ALL(a) (a).begin(), (a).end() #define SZ(a) (int)(a).size() #define PB push_back #define LL long long #define mod 10007 #define inf 107 #define eps 1e-12 using namespace std; int buf[20]; int read() { int x = 0; char ch = getchar(); bool f = 0; while (ch < '0' || ch > '9') { if (ch == '-') f = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return f ? -x : x; } void write(int x) { if (!x) { putchar(48); return; } int l = 0; if (x < 0) putchar('-'), x = -x; while (x) buf[++l] = x % 10, x = x / 10; while (l) putchar(buf[l--] + 48); } //-------------------------chc------------------------------// const int maxn = 10005; int a[maxn]; int n; typedef pair pii; int cnt; vector v; void debug() { FOR(i, 1, n + 1) printf("a = %d\n", a[i]); } void crane(int l, int r, int m) { cnt++; v.push_back(pii(l, r)); int num = (r - l + 1) / 2; FOR(i, 0, num) swap(a[l + i], a[m + i]); //printf("l = %d, r = %d, m = %d\n", l, r, m); //debug(); } int find(int cur) { int ret; FOR(i, cur, n + 1) if (a[i] == cur) { ret = i; break; } return ret; } void solve() { int cur = 1; while (cur <= n) { int pos = find(cur); if (pos == cur) { cur++; continue; } int l = cur, r = pos; if ((pos - cur + 1) & 1) l++; crane(l, r, (l + r + 1)/2); pos -= ((r - l + 1) / 2); if (pos == cur) { cur++; continue; } l = cur; r = pos + (pos - l - 1); crane(l, r, (l + r + 1)/2); cur++; } } int main() { //IN(); OUT(); int t = read(); while (t--) { v.clear(); cnt = 0; SF(n); FOR(i, 1, n + 1) SF(a[i]); solve(); PF(cnt); FOR(i, 0, SZ(v)) printf("%d %d\n", v[i].first, v[i].second); //debug(); } return 0; }