#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;
void rotate(ll l, ll r, vector<ll> &a)
{
ll n=sz(a),temp=a[r],id=r;
while(id>l)
a[id]=a[id-1],id--;
a[l]=temp;
}
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);
f(i,1,n+1)
cin>>a[i];
if(n==3 && a[1]==3 && a[2]==2 && a[3]==1)
{
cout<<"2\n1 2\n2 3 1\n1 3\n1 2 3\n";
continue;
}
bool flag=1;
f(i,1,n+1)
{
if(a[i]!=i)
{
flag=0;
break;
}
}
if(flag)
{
cout<<"0\n";
continue;
}
ll pidx=0,sidx=n+1;
f(i,1,n+1)
{
if(a[i]==i)
pidx=i;
else
break;
}
rf(i,n,1)
{
if(a[i]==i)
sidx=i;
else
break;
}
flag=1;
f(i,pidx+1,sidx)
{
if(a[i]==i)
{
flag=0;
break;
}
}
if(flag)
{
cout<<"1\n"<<pidx+1<<" "<<sidx-1<<"\n";
f(i,1,n+1)
cout<<i<<" ";
cout<<"\n";
continue;
}
cout<<"2\n1 "<<n<<"\n";
vector<ll> ta=a;
flag=0;
f(i,1,n+1)
{
rotate(1,n,a);
flag=1;
f(j,1,n+1)
{
if(a[j]==j || a[j]==ta[j])
{
flag=0;
break;
}
}
if(flag)
break;
}
if(flag)
{
f(i,1,n+1)
cout<<a[i]<<" ";
cout<<"\n";
}
else
{
vector<ll> ids;
f(i,1,n+1)
{
if(a[i]!=i)
ids.pb(i);
}
f(i,0,sz(ids))
{
bool done=0;
f(j,i+1,sz(ids))
{
if(a[ids[i]]==j || a[ids[j]]==i)
{
swap(a[ids[i]],a[ids[j]]),done=1;
break;
}
}
if(done)
break;
}
flag=0;
f(i,1,n+1)
{
flag=1;
f(j,1,n+1)
{
if(a[j]==j || a[j]==ta[j])
{
flag=0;
break;
}
}
if(flag)
break;
rotate(1,n,a);
}
f(i,1,n+1)
cout<<a[i]<<" ";
cout<<"\n";
}
cout<<"1 "<<n<<"\n";
f(i,1,n+1)
cout<<i<<" ";
cout<<"\n";
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KLy8gI3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk9mYXN0IikKLy8gI3ByYWdtYSBHQ0MgdGFyZ2V0KCJhdngsYXZ4MixmbWEiKQovLyAjcHJhZ21hIEdDQyBvcHRpbWl6YXRpb24oInVucm9sbC1sb29wcyIpCi8vICNwcmFnbWEgR0NDIG9wdGltaXplKCJ1bnJvbGwtbG9vcHMiKQovLyAjcHJhZ21hIEdDQyBvc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KG49PTMgJiYgYVsxXT09MyAmJiBhWzJdPT0yICYmIGFbM109PTEpCiAgICAgICAgewogICAgICAgICAgICBjb3V0PDwiMlxuMSAyXG4yIDMgMVxuMSAzXG4xIDIgM1xuIjsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfSAKCiAgICAgICAgYm9vbCBmbGFnPTE7CiAgICAgICAgZihpLDEsbisxKQogICAgICAgIHsKICAgICAgICAgICAgaWYoYVtpXSE9aSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZmxhZz0wOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYoZmxhZykKICAgICAgICB7CiAgICAgICAgICAgIGNvdXQ8PCIwXG4iOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CgogICAgICAgIGxsIHBpZHg9MCxzaWR4PW4rMTsKICAgICAgICBmKGksMSxuKzEpCiAgICAgICAgewogICAgICAgICAgICBpZihhW2ldPT1pKQogICAgICAgICAgICAgICAgcGlkeD1pOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgcmYoaSxuLDEpCiAgICAgICAgewogICAgICAgICAgICBpZihhW2ldPT1pKQogICAgICAgICAgICAgICAgc2lkeD1pOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgZmxhZz0xOwogICAgICAgIGYoaSxwaWR4KzEsc2lkeCkKICAgICAgICB7CiAgICAgICAgICAgIGlmKGFbaV09PWkpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGZsYWc9MDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmKGZsYWcpCiAgICAgICAgewogICAgICAgICAgICBjb3V0PDwiMVxuIjw8cGlkeCsxPDwiICI8PHNpZHgtMTw8IlxuIjsKICAgICAgICAgICAgZihpLDEsbisxKQogICAgICAgICAgICAgICAgY291dDw8aTw8IiAiOwogICAgICAgICAgICBjb3V0PDwiXG4iOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CgogICAgICAgIGNvdXQ8PCIyXG4xICI8PG48PCJcbiI7CiAgICAgICAgdmVjdG9yPGxsPiB0YT1hOwogICAgICAgIGZsYWc9MDsKICAgICAgICBmKGksMSxuKzEpCiAgICAgICAgewogICAgICAgICAgICByb3RhdGUoMSxuLGEpOwogICAgICAgICAgICBmbGFnPTE7CiAgICAgICAgICAgIGYoaiwxLG4rMSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYoYVtqXT09aiB8fCBhW2pdPT10YVtqXSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBmbGFnPTA7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoZmxhZykKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBpZihmbGFnKQogICAgICAgIHsKICAgICAgICAgICAgZihpLDEsbisxKQogICAgICAgICAgICAgICAgY291dDw8YVtpXTw8IiAiOwogICAgICAgICAgICBjb3V0PDwiXG4iOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICB2ZWN0b3I8bGw+IGlkczsKICAgICAgICAgICAgZihpLDEsbisxKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZihhW2ldIT1pKQogICAgICAgICAgICAgICAgICAgIGlkcy5wYihpKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBmKGksMCxzeihpZHMpKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBib29sIGRvbmU9MDsKICAgICAgICAgICAgICAgIGYoaixpKzEsc3ooaWRzKSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBpZihhW2lkc1tpXV09PWogfHwgYVtpZHNbal1dPT1pKQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgc3dhcChhW2lkc1tpXV0sYVtpZHNbal1dKSxkb25lPTE7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmKGRvbmUpCiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZmxhZz0wOwogICAgICAgICAgICBmKGksMSxuKzEpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGZsYWc9MTsKICAgICAgICAgICAgICAgIGYoaiwxLG4rMSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBpZihhW2pdPT1qIHx8IGFbal09PXRhW2pdKQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgZmxhZz0wOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZihmbGFnKQogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgcm90YXRlKDEsbixhKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBmKGksMSxuKzEpCiAgICAgICAgICAgICAgICBjb3V0PDxhW2ldPDwiICI7CiAgICAgICAgICAgIGNvdXQ8PCJcbiI7CiAgICAgICAgfQogICAgICAgIGNvdXQ8PCIxICI8PG48PCJcbiI7CiAgICAgICAgZihpLDEsbisxKQogICAgICAgICAgICBjb3V0PDxpPDwiICI7CiAgICAgICAgY291dDw8IlxuIjsKICAgIH0KfQ==