#include<bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC optimize("no-stack-protector")
// #define ll __int128
#define ll long long
// #define ll int
#define f(i,a,b) for(ll i=a;i<b;i++)
#define mod 1000000007
// #define mod 998244353
#define mp make_pair
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define ff first
#define ss second
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define sc(a) scanf("%lld",&a)
#define pf printf
#define sz(a) (int)(a.size())
#define psf push_front
#define ppf pop_front
#define ppb pop_back
#define pb push_back
#define pq priority_queue
#define all(s) s.begin(),s.end()
#define sp(a) setprecision(a)
#define rz resize
#define ld long double
#define inf (ll)1e18
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define eb emplace_back
const double pi = acos(-1);
ll binpow(ll a, ll b){ll res=1;while(b!=0){if(b&1)res*=a;a*=a;b>>=1;}return res;}
ll binpow(ll a, ll b, ll md){ll res=1;a%=md;if(a==0)return 0;while(b!=0){if(b&1)res*=a,res%=md;a*=a,a%=md;b>>=1;}return res%md;}
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("xortransform.in","r",stdin);
// freopen("xortransform.out","w",stdout);
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
int z=1;
cin>>z;
f(i,1,z+1)
{
//cout<<"Case #"<<i<<": ";
ll n;
cin>>n;
vector<ll> a(n+1),pos(n+1);
f(i,1,n+1)
cin>>a[i],pos[a[i]]=i;
vector<pair<ll,ll> > ans;
bool flag=1;
while(flag)
{
flag=0;
f(i,1,n)
{
if(pos[i]>pos[i+1])
ans.pb({pos[i+1],pos[i]}),swap(pos[i],pos[i+1]),flag=1;
}
}
cout<<sz(ans)<<"\n";
f(i,0,sz(ans))
cout<<ans[i].ff<<" "<<ans[i].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Y2luPj5uOwogICAgICAgIHZlY3RvcjxsbD4gYShuKzEpLHBvcyhuKzEpOwogICAgICAgIGYoaSwxLG4rMSkKICAgICAgICAgICAgY2luPj5hW2ldLHBvc1thW2ldXT1pOwogICAgICAgIHZlY3RvcjxwYWlyPGxsLGxsPiA+IGFuczsKICAgICAgICBib29sIGZsYWc9MTsKICAgICAgICB3aGlsZShmbGFnKQogICAgICAgIHsKICAgICAgICAgICAgZmxhZz0wOwogICAgICAgICAgICBmKGksMSxuKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZihwb3NbaV0+cG9zW2krMV0pCiAgICAgICAgICAgICAgICAgICAgYW5zLnBiKHtwb3NbaSsxXSxwb3NbaV19KSxzd2FwKHBvc1tpXSxwb3NbaSsxXSksZmxhZz0xOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvdXQ8PHN6KGFucyk8PCJcbiI7CiAgICAgICAgZihpLDAsc3ooYW5zKSkKICAgICAgICAgICAgY291dDw8YW5zW2ldLmZmPDwiICI8PGFuc1tpXS5zczw8IlxuIjsKICAgIH0KfQ==