#define STRESS
/**
*AUTHOR:Mayank Padia*
*Birla Institute of Technology,Mesra*
**/
#include<bits/stdc++.h>
typedef long long ll;
typedef double ld;
#define vll vector<ll>
#define vvll vector< vll >
#define vld vector< ld >
#define vvld vector< vld >
#define pll pair<ll ,ll >
#define vllp vector< pll >
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define endl "\n"
#define test ll t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define F first
#define S second
#define MAX 1000000007
#define cf_MOD 998244353
#define forn(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
#define forr(i,n) for(ll (i) = (n)-1 ; (i)>=0 ; --(i))
#define forab(i,a,b,c) for(ll (i) = a ; (i) <= (b) ; (i)+=(c))
#define trace1(x) cerr<<#x<<": "<<x<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
using namespace std;
#ifdef STRESS
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using rnd = uniform_int_distribution<int>;
#endif
vll sieve;
void Sieve(int N){
const ll maxn = N;
sieve.resize(maxn);
forn(i,maxn) sieve[i] = i;
sieve[1] = -1;
sieve[0] = -1;
forab(i,2,maxn,1) if(i == sieve[i]) for(ll j = 2*i ; j < maxn ; j+=i) if(sieve[j] == j) sieve[j] = i;
}
ll extended_GCD(ll a , ll b , ll &x , ll &y){
if(a == 0){
x = 0;
y = 1;
return b;
}
ll x1 , y1;
ll gcd = extended_GCD(b%a , a , x1 , y1);
x = y1 - (b/a)*x1;
y = x1;
return gcd;
}
ll power(ll a, ll b, ll m = MOD) {
a %= m;
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
ll modinv(ll a , ll mod = MOD){
ll x , y;
extended_GCD(a , mod , x , y);
if(x < 0) x += mod;
return x;
}
//s=bitset<64>(val).to_string();
///////////////////////////////////////////////////////////////////////
bool comp(pair<ll,ll> a, pair<ll,ll> b)
{
if(a.S>b.S)
return true;
else if(a.S == b.S)
{
if(a.F<b.F)
return true;
return false;
}
else{
return false;
}
}
void solve(){
ll n;
//memset(a,-1,sizeof(a));
#ifdef STRESS
n = 3;
#else
cin>>n;
#endif
ll a[n];
ll b[n];
for (int i = 0; i < n; ++i)
{
#ifdef STRESS
a[i] = rnd(0, 10)(rng);
#else
cin>>a[i];
#endif
b[i] = a[i];
}
#ifdef STRESS
vector<int> sta(a, a + n);
#endif
sort(b,b+n);
vector<ll> v;
map<ll,vll> ma;
ll x = 0;
for (int i = 0; i < n; ++i)
{
for (int j = i+1; j < n; ++j)
{
if(i!=j)
{
if(a[i]>a[j])
{
ma[j].pb(i);
x++;
}
}
}
}
vector<pair<ll,ll> > vp;
for(int i = n-1; i >= 0; --i)
{
if(ma[i].size() == 0)
continue;
ll in = -1;
for (int j = 0; j < ma[i].size(); ++j)
{
if(a[ma[i][j]] == b[i])
{
in = j;
break;
}
}
ll ff = 0;
for (int j = 0; j < ma[i].size(); ++j)
{
if(ma[i][j] != in)
{
vp.pb({ma[i][j] + 1,i+1});
swap(a[i], a[ma[i][j]]);
}
else{
ff = 1;
}
}
if(ff == 1){
vp.pb({in + 1, i + 1});
if(vp.size()>x)
{
cout<<"Exceeded at "<<i<<" "<<ma[i].size()<<endl;
return;
}
swap(a[i], a[in]);
}
}
#ifndef STRESS
cout<<vp.size()<<endl;
for (int i = 0; i < vp.size(); ++i)
{
cout<<vp[i].F<<" "<<vp[i].S<<endl;
}
#endif
#ifdef STRESS
auto temp = sta;
for (auto p: vp)
swap(temp[p.first - 1], temp[p.second - 1]);
if (is_sorted(temp.begin(), temp.end()))
cout << "OK" << endl;
else {
cout << sta.size() << '\n';
for (int i: sta)
cout << i << ' ';
cout << endl;
}
#else
cout<<vp.size()<<endl;
for (int i = 0; i < vp.size(); ++i)
{
cout<<vp[i].F<<" "<<vp[i].S<<endl;
}
#endif
}
int main(){
#ifndef STRESS
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
#endif
ios::sync_with_stdio(0); cin.tie(0);
int t=1;
//cin>>t;
#ifdef STRESS
cin >> t;
#endif
while(t--){
solve();
}
#ifndef ONLINE_JUDGE
cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
#endif
return 0;
}
I2RlZmluZSBTVFJFU1MKLyoqCiAgICAgICAgKkFVVEhPUjpNYXlhbmsgUGFkaWEqCiAgICAgICAgKkJpcmxhIEluc3RpdHV0ZSBvZiBUZWNobm9sb2d5LE1lc3JhKgoqKi8KI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgZG91YmxlIGxkOwojZGVmaW5lIHZsbCB2ZWN0b3I8bGw+CiNkZWZpbmUgdnZsbCB2ZWN0b3I8IHZsbCA+CiNkZWZpbmUgdmxkIHZlY3RvcjwgbGQgPgojZGVmaW5lIHZ2bGQgdmVjdG9yPCB2bGQgPgojZGVmaW5lIHBsbCBwYWlyPGxsICxsbCA+CiNkZWZpbmUgdmxscCB2ZWN0b3I8IHBsbCA+CiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZ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GEpKTsKI2lmZGVmIFNUUkVTUwogICAgbiA9IDM7CiNlbHNlCiAgICBjaW4+Pm47CiNlbmRpZgogICAgbGwgYVtuXTsKICAgIGxsIGJbbl07CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkKICAgIHsKI2lmZGVmIFNUUkVTUwogICAgICAgIGFbaV0gPSBybmQoMCwgMTApKHJuZyk7CiNlbHNlCiAgICAgICAgY2luPj5hW2ldOwojZW5kaWYKICAgICAgICBiW2ldID0gYVtpXTsKICAgIH0KI2lmZGVmIFNUUkVTUwogICAgdmVjdG9yPGludD4gc3RhKGEsIGEgKyBuKTsKI2VuZGlmCiAgICBzb3J0KGIsYituKTsKICAgIHZlY3RvcjxsbD4gdjsKICAgIG1hcDxsbCx2bGw+IG1hOwogICAgbGwgeCA9IDA7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkKICAgIHsKICAgICAgICBmb3IgKGludCBqID0gaSsxOyBqIDwgbjsgKytqKQogICAgICAgIHsKICAgICAgICAgICAgaWYoaSE9aikKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYoYVtpXT5hW2pdKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIG1hW2pdLnBiKGkpOwogICAgICAgICAgICAgICAgICAgIHgrKzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIHZlY3RvcjxwYWlyPGxsLGxsPiA+IHZwOwogICAgZm9yKGludCBpID0gbi0xOyBpID49IDA7IC0taSkKICAgIHsKICAgICAgICBpZihtYVtpXS5zaXplKCkgPT0gMCkKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgbGwgaW4gPSAtMTsKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IG1hW2ldLnNpemUoKTsgKytqKQogICAgICAgIHsKICAgICAgICAgICAgaWYoYVttYVtpXVtqXV0gPT0gYltpXSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaW4gPSBqOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgbGwgZmYgPSAwOwogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbWFbaV0uc2l6ZSgpOyArK2opCiAgICAgICAgewogICAgICAgICAgICBpZihtYVtpXVtqXSAhPSBpbikKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdnAucGIoe21hW2ldW2pdICsgMSxpKzF9KTsKICAgICAgICAgICAgICAgIHN3YXAoYVtpXSwgYVttYVtpXVtqXV0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2V7CiAgICAgICAgICAgICAgICBmZiA9IDE7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYoZmYgPT0gMSl7CiAgICAgICAgdnAucGIoe2luICsgMSwgaSArIDF9KTsKICAgICAgICBpZih2cC5zaXplKCk+eCkKICAgICAgICB7CiAgICAgICAgICAgIGNvdXQ8PCJFeGNlZWRlZCBhdCAiPDxpPDwiICI8PG1hW2ldLnNpemUoKTw8ZW5kbDsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICBzd2FwKGFbaV0sIGFbaW5dKTsKICAgICAgICB9CiAgICB9CiNpZm5kZWYgU1RSRVNTCiAgICBjb3V0PDx2cC5zaXplKCk8PGVuZGw7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IHZwLnNpemUoKTsgKytpKQogICAgewogICAgICAgIGNvdXQ8PHZwW2ldLkY8PCIgIjw8dnBbaV0uUzw8ZW5kbDsKICAgIH0KI2VuZGlmCiNpZmRlZiBTVFJFU1MKICAgIGF1dG8gdGVtcCA9IHN0YTsKICAgIGZvciAoYXV0byBwOiB2cCkKICAgICAgICBzd2FwKHRlbXBbcC5maXJzdCAtIDFdLCB0ZW1wW3Auc2Vjb25kIC0gMV0pOwogICAgaWYgKGlzX3NvcnRlZCh0ZW1wLmJlZ2luKCksIHRlbXAuZW5kKCkpKQogICAgICAg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