// Model solution for problem I // Author: Arkadiusz Pawlik #include #include using namespace std; int s, r; int input[20000]; int ta[100000], tb[100000]; struct order_cmp { bool operator()(int a, int b) { return input[a] < input[b]; } }; void print_swap(int a, int b) { ta[r] = a; tb[r++] = b; int d = (b+1-a)/2; for (int i = a; i < a + d; ++i) swap(input[i], input[i+d]); } void make_dirty_swap(int i, int j, int s) { if (i == j) return; if (j - i > s - j) { int l = j - i; if (l % 2 == 0) l--; print_swap(j-l, j); j -= (l+1)/2; } print_swap(i, j + (j-i)-1); } int t_() { cin >> s; r = 0; for (int i = 0; i < s; ++i) { cin >> input[i]; input[i] -= 1; } for (int i = 0; i < s; ++i) { int m_i = i; while (input[m_i] != i) ++m_i; make_dirty_swap(i, m_i, s); } cout << r << endl; for (int i = 0; i < r; ++i) { cout << ta[i]+1 << ' ' << tb[i]+1 << endl; } } int main() { ios::sync_with_stdio(true); int d; cin >> d; while (d--) t_(); }