#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;

//vector<int>cnt(100001,0);
int main() {
	int n;
	cin>>n;
	vector<int>v(n);
	map<int,int>cnt;
	int max1=0;
	int val=-1;
	for(int i=0;i<n;i++)
	{
	cin>>v[i];
	cnt[v[i]]++;
	//cout<<v[i]<<" "<<cnt[v[i]]<<endl;
	if(cnt[v[i]]>max1)
	{
	    max1=cnt[v[i]];
	    val=v[i];
	}
	}

	int ind;
	for(int i=0;i<n;i++){
	if(v[i]==val){
	ind=i;
	break;}}
	//cout<<max1<<" ";
	cout<<n-max1<<endl;
	for(int i=ind-1;i>=0;i--)
	{
	    cout<<"1 "<<i+1<<" "<<i+2<<endl;
	}
	for(int i=ind+1;i<n;i++)
	{
	    if(v[i]==val)
	    continue;

	    cout<<"2 "<<i+1<<" "<<i<<endl;
	}
	return 0;
}


////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    string st;
    while(cin>>n)
    {
        vi v;
        map<int,int> mp;
        a=b=0;
        rep(i,n)
        {
            cin>>x;
            v.pb(x);
            mp[x]++;
            if(mp[x]>a) a=mp[x],b=x,p=i;
        }
        if(a==n) cout<<0<<en;
        else
        {
            sort(all(v));
            cout<<n-a<<en;
            q=LB(v,b);
            peR(k,q)
            {
                cout<<1<<" "<<k-1+1<<" "<<k+1<<en;
            }
            for(k=p+1;k<n;k++)
            {
                cout<<1<<" "<<k<<" "<<k+1<<en;
            }
        }
    }
}


////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    string st;
    while(cin>>n)
    {
        vi v;
        map<int,int> mp;
        a=b=0;
        rep(i,n)
        {
            cin>>x;
            v.pb(x);
            mp[x]++;
            if(mp[x]>a) a=mp[x],b=x,p=i;
        }
        if(a==n) cout<<0<<en;
        else
        {
            sort(all(v));
            cout<<n-a<<en;
            q=LB(v,b);
            peR(k,q)
            {
                cout<<1<<" "<<k-1+1<<" "<<k+1<<en;
            }
            for(k=p+1;k<n;k++)
            {
                cout<<2<<" "<<k+1<<" "<<k<<en;
            }
        }
    }
}


////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    string st;
    while(cin>>n)
    {
        vi v;
        map<int,int> mp;
        a=b=0;
        rep(i,n)
        {
            cin>>x;
            v.pb(x);
            mp[x]++;
            if(mp[x]>a) a=mp[x],b=x,p=i;
        }
        cout<<n-a<<en;
        for(i=p-1;i>=0;i--)
        {
            if(v[i]!=b) cout<<2<<" "<<i+2<<" "<<i+1<<en;
        }
        for(i=p+1;i<n;i++)
        {
            if(v[i]!=b) cout<<1<<" "<<i<<" "<<i+1<<en;
        }
    }
}


////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    string st;
    while(cin>>n)
    {
        vi v;
        map<int,int> mp;
        a=b=0;
        rep(i,n)
        {
            cin>>x;
            v.pb(x);
            mp[x]++;
            if(mp[x]>a) a=mp[x],b=x,p=i;
        }
        cout<<n-a<<en;
        for(i=p-1;i>=0;i--)
        {
            if(v[i]>b) cout<<2<<" "<<i+1<<" "<<i+2<<en;
            else if(v[i]<b) cout<<1<<" "<<i+1<<" "<<i+2<<en;
        }
        for(i=p+1;i<n;i++)
        {
            if(v[i]>b) cout<<2<<" "<<i+1<<" "<<i<<en;
            else if(v[i]<b) cout<<1<<" "<<i+1<<" "<<i<<en;
        }
    }
}


////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    string st;
    while(cin>>n)
    {
        vi v;
        map<int,int> mp;
        a=b=0;
        rep(i,n)
        {
            cin>>x;
            v.pb(x);
            mp[x]++;
            if(mp[x]>a) a=mp[x],b=x,p=i;
        }
        cout<<n-a<<en;
        for(i=p-1;i>=0;i--)
        {
            if(v[i]>b) cout<<2<<" "<<i+2<<" "<<i+1<<en;
            else if(v[i]<b) cout<<1<<" "<<i+1<<" "<<i+2<<en;
        }
        for(i=p+1;i<n;i++)
        {
            if(v[i]>b) cout<<2<<" "<<i+1<<" "<<i<<en;
            else if(v[i]<b) cout<<1<<" "<<i<<" "<<i+1<<en;
        }
    }
}


////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    string st;
    while(cin>>n)
    {
        vi v;
        map<int,int> mp;
        a=b=0;
        rep(i,n)
        {
            cin>>x;
            v.pb(x);
            mp[x]++;
            if(mp[x]>a) a=mp[x],b=x,p=i;
        }
        cout<<n-a<<en;
        for(i=p-1;i>=0;i--)
        {
            if(v[i]>b) cout<<2<<" "<<i+2<<" "<<i+1<<en;
            else if(v[i]<b) cout<<1<<" "<<i+1<<" "<<i+2<<en;
        }
        for(i=p+1;i<n;i++)
        {
            if(v[i]>b) cout<<2<<" "<<i+1<<" "<<i<<en;
            else if(v[i]<b) cout<<1<<" "<<i+1<<" "<<i<<en;
        }
    }
}


////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    string st;
    while(cin>>n)
    {
        vi v;
        map<int,int> mp;
        a=b=0;
        rep(i,n)
        {
            cin>>x;
            v.pb(x);
            mp[x]++;
            if(mp[x]>a) a=mp[x],b=x,p=i;
        }
        sort(all(v));
        cout<<n-a<<en;
        q=LB(v,b);
        peR(k,q)
        {
            cout<<1<<" "<<k-1+1<<" "<<k+1<<en;
        }
        for(k=p+1;k<n;k++)
        {
            cout<<2<<" "<<k+1<<" "<<k<<en;
        }
    }
}


////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    string st;
    while(cin>>n)
    {
        vi v;
        map<int,int> mp;
        a=b=0;
        rep(i,n)
        {
            cin>>x;
            v.pb(x);
            mp[x]++;
            if(mp[x]>a) a=mp[x],b=x,p=i;
        }
        cout<<n-a<<en;
        for(i=p-1;i>=0;i--)
        {
            if(v[i]>b) cout<<2<<" "<<i+2<<" "<<i+1<<en;
            else if(v[i]<b) cout<<1<<" "<<i+1<<" "<<i+2<<en;
        }
        for(i=p+1;i<n;i++)
        {
            if(v[i]>b) cout<<1<<" "<<i<<" "<<i+1<<en;
            else if(v[i]<b) cout<<2<<" "<<i+1<<" "<<i<<en;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define forkn(i, k, n) for (int i = k; i < (int)n; i++)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) ((int)(a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef pair <string,int> psi;
typedef map <string,int> msi;

template <class T> void relax(T &a, T b) { a = min(a, b); }
template <class T> void mrelax(T &a, T b) { a = max(a, b); }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];

    int best = 0;
    unordered_map<int,int> cnt;
    forn(i, n)
    {
        cnt[a[i]]++;
        if (cnt[a[i]] > cnt[a[best]])
            best = i;
    }

    cout << (n-cnt[a[best]]) << "\n";
    forn(i, n)
        if (a[i] > a[best])
        {
            cout << "2 " << (i+1) << " " << best+1 << "\n";
        } else if (a[i] < a[best])
        {
            cout << "1 " << (i+1) << " " << best+1 << "\n";
        }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define forkn(i, k, n) for (int i = k; i < (int)n; i++)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) ((int)(a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef pair <string,int> psi;
typedef map <string,int> msi;

template <class T> void relax(T &a, T b) { a = min(a, b); }
template <class T> void mrelax(T &a, T b) { a = max(a, b); }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];

    unordered_map<int,int> cnt;
    int best = 0;
    forn(i, n)
    {
        cnt[a[i]]++;
        if (cnt[a[i]] > cnt[a[best]])
            best = i;
    }

    cout << n-cnt[a[best]] << "\n";
    forn(i, n)
        if (a[i] == a[best])
        {
            for (int j = i-1; j >= 0; j--)
            {
                if (a[j] == a[best]) break;
                cout << (a[j+1] > a[j] ? "1 " : "2 ");
                cout << j+1 << " " << j+2 << "\n";
            }
        }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define forkn(i, k, n) for (int i = k; i < (int)n; i++)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) ((int)(a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef pair <string,int> psi;
typedef map <string,int> msi;

template <class T> void relax(T &a, T b) { a = min(a, b); }
template <class T> void mrelax(T &a, T b) { a = max(a, b); }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];

    unordered_map<int,int> cnt;
    int best = 0;
    forn(i, n)
    {
        cnt[a[i]]++;
        if (cnt[a[i]] > cnt[a[best]])
            best = i;
    }

    for (int i = n-1; i >= 0; i--)
        if (cnt[a[i]] == cnt[a[best]])
        {
            best = i; break;
        }

    a.pb(a[best]);

    cout << n-cnt[a[best]] << "\n";
    forn(i, n+1)
        if (a[i] == a[best])
        {
            for (int j = i-1; j >= 0; j--)
            {
                if (a[j] == a[best]) break;
                cout << (a[j+1] > a[j] ? "1 " : "2 ");
                cout << j+1 << " " << j+2 << "\n";
                a[j] = a[j+1];
            }
        }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define forkn(i, k, n) for (int i = k; i < (int)n; i++)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) ((int)(a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef pair <string,int> psi;
typedef map <string,int> msi;

template <class T> void relax(T &a, T b) { a = min(a, b); }
template <class T> void mrelax(T &a, T b) { a = max(a, b); }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];

    unordered_map<int,int> cnt;
    int best = 0;
    forn(i, n)
    {
        cnt[a[i]]++;
        if (cnt[a[i]] > cnt[a[best]])
            best = i;
    }

    for (int i = n-1; i >= 0; i--)
        if (cnt[a[i]] == cnt[a[best]])
        {
            best = i; break;
        }

    a.pb(a[best]);

    cout << n-cnt[a[best]] << "\n";
    forn(i, n+1)
        if (a[i] == a[best])
        {
            for (int j = i-1; j >= 0; j--)
            {
                if (a[j] == a[best]) break;
                cout << (a[j+1] > a[j] ? "1 " : "2 ");
                cout << j+1 << " " << j+2 << "\n";
            }
        }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define forkn(i, k, n) for (int i = k; i < (int)n; i++)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) ((int)(a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef pair <string,int> psi;
typedef map <string,int> msi;

template <class T> void relax(T &a, T b) { a = min(a, b); }
template <class T> void mrelax(T &a, T b) { a = max(a, b); }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];

    unordered_map<int,int> cnt;
    int best = 0;
    forn(i, n)
    {
        cnt[a[i]]++;
        if (cnt[a[i]] > cnt[a[best]])
            best = i;
    }
    cout << n-cnt[a[best]] << "\n";

    for (int i = n-1; i >= 0; i--)
        if (a[i] == a[best])
        {
            forkn(j, i+1, n)
            {
                cout << (a[j-1] > a[j] ? "1 " : "2 ");
                cout << j << " " << j+1 << "\n";
                a[j] = a[j-1];
            }
            break;
        }

    forn(i, n+1)
        if (a[i] == a[best])
        {
            for (int j = i-1; j >= 0; j--)
            {
                if (a[j] == a[best]) break;
                cout << (a[j+1] > a[j] ? "1 " : "2 ");
                cout << j+1 << " " << j+2 << "\n";
                a[j] = a[j+1];
            }
        }

    for( int x : a ) cout << x << " ";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define forkn(i, k, n) for (int i = k; i < (int)n; i++)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) ((int)(a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef pair <string,int> psi;
typedef map <string,int> msi;

template <class T> void relax(T &a, T b) { a = min(a, b); }
template <class T> void mrelax(T &a, T b) { a = max(a, b); }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];

    unordered_map<int,int> cnt;
    int best = 0;
    forn(i, n)
    {
        cnt[a[i]]++;
        if (cnt[a[i]] > cnt[a[best]])
            best = i;
    }
    cout << n-cnt[a[best]] << "\n";

    for (int i = n-1; i >= 0; i--)
        if (a[i] == a[best])
        {
            forkn(j, i+1, n)
            {
                cout << (a[j-1] > a[j] ? "1 " : "2 ");
                cout << j+1 << " " << j << "\n";
                a[j] = a[j-1];
            }
            break;
        }

    forn(i, n+1)
        if (a[i] == a[best])
        {
            for (int j = i-1; j >= 0; j--)
            {
                if (a[j] == a[best]) break;
                cout << (a[j+1] > a[j] ? "1 " : "2 ");
                cout << j+1 << " " << j+2 << "\n";
                a[j] = a[j+1];
            }
        }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define forkn(i, k, n) for (int i = k; i < (int)n; i++)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) ((int)(a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef pair <string,int> psi;
typedef map <string,int> msi;

template <class T> void relax(T &a, T b) { a = min(a, b); }
template <class T> void mrelax(T &a, T b) { a = max(a, b); }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];

    unordered_map<int,int> cnt;
    int best = 0;
    forn(i, n)
    {
        cnt[a[i]]++;
        if (cnt[a[i]] > cnt[a[best]])
            best = i;
    }

    for (int i = n-1; i >= 0; i--)
        if (cnt[a[i]] == cnt[a[best]])
        {
            best = i; break;
        }

    cout << n-cnt[a[best]] << "\n";

    for (int i = n-1; i >= 0; i--)
        if (a[i] == a[best])
        {
            forkn(j, i+1, n)
            {
                cout << (a[j-1] > a[j] ? "1 " : "2 ");
                cout << j << " " << j+1 << "\n";
                a[j] = a[j-1];
            }
            break;
        }

    forn(i, n+1)
        if (a[i] == a[best])
        {
            for (int j = i-1; j >= 0; j--)
            {
                if (a[j] == a[best]) break;
                cout << (a[j+1] > a[j] ? "1 " : "2 ");
                cout << j+1 << " " << j+2 << "\n";
                a[j] = a[j+1];
            }
        }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define forkn(i, k, n) for (int i = k; i < (int)n; i++)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) ((int)(a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef pair <string,int> psi;
typedef map <string,int> msi;

template <class T> void relax(T &a, T b) { a = min(a, b); }
template <class T> void mrelax(T &a, T b) { a = max(a, b); }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];

    unordered_map<int,int> cnt;
    int best = 0;
    forn(i, n)
    {
        cnt[a[i]]++;
        if (cnt[a[i]] > cnt[a[best]])
            best = i;
    }
    cout << n-cnt[a[best]] << "\n";

    for (int i = n-1; i >= 0; i--)
        if (a[i] == a[best])
        {
            forkn(j, i+1, n)
            {
                cout << (a[j-1] > a[j] ? "1 " : "2 ");
                cout << j << " " << j+1 << "\n";
                a[j] = a[j-1];
            }
            break;
        }

    forn(i, n+1)
        if (a[i] == a[best])
        {
            for (int j = i-1; j >= 0; j--)
            {
                if (a[j] == a[best]) break;
                cout << (a[j+1] > a[j] ? "1 " : "2 ");
                cout << j+1 << " " << j+2 << "\n";
                a[j] = a[j+1];
            }
        }

    for (int i : a)
        if (a[i] != a[best])
            cout << "NOO\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define forkn(i, k, n) for (int i = k; i < (int)n; i++)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) ((int)(a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef pair <string,int> psi;
typedef map <string,int> msi;

template <class T> void relax(T &a, T b) { a = min(a, b); }
template <class T> void mrelax(T &a, T b) { a = max(a, b); }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];

    unordered_map<int,int> cnt;
    int best = 0;
    forn(i, n)
    {
        cnt[a[i]]++;
        if (cnt[a[i]] > cnt[a[best]])
            best = i;
    }
    cout << n-cnt[a[best]] << "\n";

    for (int i = n-1; i >= 0; i--)
        if (a[i] == a[best])
        {
            forkn(j, i+1, n)
            {
                cout << (a[j-1] > a[j] ? "1 " : "2 ");
                cout << j << " " << j+1 << "\n";
                a[j] = a[j-1];
            }
            break;
        }

    forn(i, n+1)
        if (a[i] == a[best])
        {
            for (int j = i-1; j >= 0; j--)
            {
                if (a[j] == a[best]) break;
                cout << (a[j+1] > a[j] ? "1 " : "2 ");
                cout << j+1 << " " << j+2 << "\n";
                a[j] = a[j+1];
            }
        }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e5+5;

int32_t main()
{
    IOS;
    int n;
    cin >> n;
    int index=-1,max=0,ele;
    map<int,int> x;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        x[a[i]]++;
        if(max<=x[a[i]])
        {
            max=x[a[i]];
            ele=a[i];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(ele!=a[i])
            ans++;
    }
    cout << ans << endl;
    for(int i=0;i<n;i++)
    {
        while(i<n)
        {
            if(a[i]==ele)
                break;
            i++;
        }
        if(i!=n)
        {
        for(int j=i-1;j>=0;j--)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j+1 << " " << j+2<< endl;;
                a[j]=ele;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j+1 << " " << j+2 << endl;;
                 a[j]=ele;
            }
            else
                break;
        }
        }
    }
    if(a[n-1]!=ele)
    {
        int i=n-1;
        while(i>=0)
        {
            if(a[i]==ele)
                break;
            i--;
        }
        i++;
        int j=i;
        for(;j<n;j++)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j << " " << j+1<< endl;;
                a[j]=ele;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j+1 << " " << j << endl;;
                 a[j]=ele;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e5+5;

int32_t main()
{
    IOS;
    int n;
    cin >> n;
    int index=-1,max=0,ele;
    map<int,int> x;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        x[a[i]]++;
        if(max<=x[a[i]])
        {
            max=x[a[i]];
            ele=a[i];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(ele!=a[i])
            ans++;
    }
    cout << ans << endl;
    for(int i=0;i<n;i++)
    {
        while(i<n)
        {
            if(a[i]==ele)
                break;
            i++;
        }
        for(int j=i-1;j>=0;j--)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j+1 << " " << j+2<< endl;;
                a[j]=ele;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j+1 << " " << j+2<< endl;;
                 a[j]=ele;
            }
            else
                break;
        }
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e5+5;

int32_t main()
{
    IOS;
    int n;
    cin >> n;
    int index=-1,max=0,ele;
    map<int,int> x;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        x[a[i]]++;
        if(max<=x[a[i]])
        {
            max=x[a[i]];
            ele=a[i];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(ele!=a[i])
            ans++;
    }
    cout << ans << endl;
    for(int i=0;i<n;i++)
    {
        while(i<n)
        {
            if(a[i]==ele)
                break;
            i++;
        }
        if(i!=n)
        {
        for(int j=i-1;j>=0;j--)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j+1 << " " << j+2<< endl;;
                a[j]=ele;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j+2 << " " << j+1 << endl;;
                 a[j]=ele;
            }
            else
                break;
        }
        }
    }
    if(a[n-1]!=ele)
    {
        int i=n-1;
        while(i>=0)
        {
            if(a[i]==ele)
                break;
            i--;
        }
        i++;
        int j=i;
        for(;j<n;j++)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j << " " << j+1<< endl;;
                a[j]=ele;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j << " " << j+1 << endl;;
                 a[j]=ele;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e5+5;

int32_t main()
{
    IOS;
    int n;
    cin >> n;
    int index=-1,max=0,ele;
    map<int,int> x;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        x[a[i]]++;
        if(max<=x[a[i]])
        {
            max=x[a[i]];
            ele=a[i];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(ele!=a[i])
            ans++;
    }
    cout << ans << endl;
    for(int i=0;i<n;i++)
    {
        while(i<n)
        {
            if(a[i]==ele)
                break;
            i++;
        }
        for(int j=i-1;j>=0;j--)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j+1 << " " << j+2<< endl;;
                a[j]=ele;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j+2 << " " << j+1 << endl;;
                 a[j]=ele;
            }
            else
                break;
        }
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e5+5;

int32_t main()
{
    IOS;
    int n;
    cin >> n;
    int index=-1,max=0,ele;
    map<int,int> x;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        x[a[i]]++;
        if(max<x[a[i]])
        {
            max=x[a[i]];
            ele=a[i];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(ele!=a[i])
            ans++;
    }
    cout << ans << endl;
    for(int i=0;i<n;i++)
    {
        while(i<n)
        {
            if(a[i]==ele)
                break;
            i++;
        }
        if(i!=n)
        {
            for(int j=i-1;j>=0;j--)
            {
                if(ele>a[j])
                {
                    cout << 1 << " " << j+1 << " " << j+2<< endl;;
                    a[j]=ele;
                }
                else if(ele<a[j])
                {
                    cout << 2 << " " << j+1 << " " << j+2 << endl;;
                     a[j]=ele;
                }
                else
                    break;
            }
        }
    }
    if(a[n-1]!=ele)
    {
        int i=n-1;
        while(i>=0)
        {
            if(a[i]==ele)
                break;
            i--;
        }
        i++;
        int j=i;
        for(;j<n;j++)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j+1 << " " << j<< endl;;
                a[j]=ele;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j+1 << " " << j << endl;;
                 a[j]=ele;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e5+5;

int32_t main()
{
    IOS;
    int n;
    cin >> n;
    int index=-1,max=0,ele;
    map<int,int> x;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        x[a[i]]++;
        if(max<=x[a[i]])
        {
            max=x[a[i]];
            ele=a[i];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(ele!=a[i])
            ans++;
    }
    cout << ans << endl;
    for(int i=0;i<n;i++)
    {
        while(i<n)
        {
            if(a[i]==ele)
                break;
            i++;
        }
        for(int j=i-1;j>=0 && a[j]!=ele;j--)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j+1 << " " << j+2<< endl;;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j+1 << " " << j+2<< endl;;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e5+5;

int32_t main()
{
    IOS;
    int n;
    cin >> n;
    int index=-1,max=0,ele;
    map<int,int> x;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        x[a[i]]++;
        if(max<=x[a[i]])
        {
            max=x[a[i]];
            ele=a[i];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(ele!=a[i])
            ans++;
    }
    cout << ans << endl;
    for(int i=0;i<n;i++)
    {
        while(i<n)
        {
            if(a[i]==ele)
                break;
            i++;
        }
        for(int j=i-1;j>=0 && a[j]!=ele;j--)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j+2 << " " << j+1<< endl;;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j+2 << " " << j+1<< endl;;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e5+5;

int32_t main()
{
    IOS;
    int n;
    cin >> n;
    int index=-1,max=0,ele;
    map<int,int> x;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        x[a[i]]++;
        if(max<=x[a[i]])
        {
            max=x[a[i]];
            ele=a[i];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(ele!=a[i])
            ans++;
    }
    cout << ans << endl;
    for(int i=0;i<n;i++)
    {
        while(i<n)
        {
            if(a[i]==ele)
                break;
            i++;
        }
        if(i!=n)
        {
        for(int j=i-1;j>=0;j--)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j+1 << " " << j+2<< endl;;
                a[j]=ele;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j+1 << " " << j+2 << endl;;
                 a[j]=ele;
            }
            else
                break;
        }
        }
    }
    if(a[n-1]!=ele)
    {
        int i=n-1;
        while(i>=0)
        {
            if(a[i]==ele)
                break;
            i--;
        }
        i++;
        int j=i;
        for(;j<n;j++)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j << " " << j+1<< endl;;
                a[j]=ele;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j << " " << j+1 << endl;;
                 a[j]=ele;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e5+5;

int32_t main()
{
    IOS;
    int n;
    cin >> n;
    int index=-1,max=0,ele;
    map<int,int> x;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        x[a[i]]++;
        if(max<=x[a[i]])
        {
            max=x[a[i]];
            ele=a[i];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(ele!=a[i])
            ans++;
    }
    cout << ans << endl;
    for(int i=0;i<n;i++)
    {
        while(i<n)
        {
            if(a[i]==ele)
                break;
            i++;
        }
        if(i!=n)
        {
        for(int j=i-1;j>=0;j--)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j+1 << " " << j+2<< endl;;
                a[j]=ele;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j+2 << " " << j+1 << endl;;
                 a[j]=ele;
            }
            else
                break;
        }
        }
    }
    if(a[n-1]!=ele)
    {
        int i=n-1;
        while(i>=0)
        {
            if(a[i]==ele)
                break;
            i--;
        }
        i++;
        int j=i;
        for(;j<n;j++)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j << " " << j+1<< endl;;
                a[j]=ele;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j+1 << " " << j << endl;;
                 a[j]=ele;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e5+5;

int32_t main()
{
    IOS;
    int n;
    cin >> n;
    int index=-1,max=0,ele;
    map<int,int> x;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        x[a[i]]++;
        if(max<=x[a[i]])
        {
            max=x[a[i]];
            ele=a[i];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(ele!=a[i])
            ans++;
    }
    cout << ans << endl;
    for(int i=0;i<n;i++)
    {
        while(i<n)
        {
            if(a[i]==ele)
                break;
            i++;
        }
        for(int j=i-1;j>=0 && a[j]!=ele;j--)
        {
            if(ele>a[j])
            {
                cout << 1 << " " << j+1 << " " << j+2<< endl;;
                a[j]=ele;
            }
            else if(ele<a[j])
            {
                 cout << 2 << " " << j+1 << " " << j+2<< endl;;
                 a[j]=ele;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
using namespace std::chrono;
#define ll long long int
ll a[200009];
ll cnt[200009];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output1.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll max=0,pos;
    for(lli=0;i<n;i++)
    {
	    cin>>a[i];
	    cnt[a[i]]++;
	    if(max<cnt[a[i]])
	    {
		    max=cnt[a[i]];
		    pos=i;
	    }
    }
    ll tar=a[pos];
    cout<<n-max<<endl;
    for(ll i=pos-1;i>=0;i--)
    {
	    if(a[i]!=tar)
		    cout<<1+(a[i]>tar)<<' '<<i+1<<' '<<i+2<<endl;
    }
    for(ll i=pos+1;i<n;i++)
    {
	    if(a[i]!=tar)
		    cout<<1+(a[i]>tar)<<' '<<i+1<<' '<<i<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
using namespace std::chrono;
#define ll long long int
ll a[200009];
ll cnt[200009];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output1.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll max=0,pos;
    for(ll i=0;i<n;i++)
    {
	    cin>>a[i];
	    cnt[a[i]]++;
	    if(max<cnt[a[i]])
	    {
		    max=cnt[a[i]];
		    pos=i;
	    }
    }
    ll tar=a[pos];
    cout<<n-max<<"\n";
    for(ll i=pos-1;i>=0;i--)
    {
	    if(a[i]!=tar)
		    cout<<1+(a[i]>tar)<<' '<<i+1<<' '<<i+2<<"\n";
    }
    for(ll i=pos+1;i<n;i++)
    {
	    if(a[i]!=tar)
		    cout<<1+(a[i]>tar)<<' '<<i+1<<' '<<i<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
using namespace std::chrono;
#define ll long long int
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output1.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    vector<ll>v,pre,suff,te,v1;
    set<ll>s;
    multiset<ll>ms;
    vector< pair<ll, pair<ll,ll> > > v2;
        for(ll i=0,temp,temp1;i<n;i++){
	cin>>temp;
	temp1=s.size();
	s.insert(temp);
	ms.insert(temp);
	v1.push_back(temp);
	if(s.size()!=temp1)
	    v.push_back(temp);
    }
    if(s.size()==1){
	cout<<0<<endl;
	return 0;
    }
    for(auto x:s){
	//cout<<ms.count(x)<<endl;
	te.push_back(ms.count(x));
    }
    pre.push_back(te[0]);
    suff.push_back(te[te.size()-1]);
    for(ll i=1;i<te.size();i++){
	pre.push_back(te[i]+pre[i-1]);
	suff.push_back(te[i]+suff[i-1]);
    }
    reverse(suff.begin(),suff.end());
    ll min1=INT_MAX,z;
    for(ll i=0;i<pre.size();i++){
	if(i!=0&&i!=pre.size()-1){
	    if(min1>=pre[i-1]+suff[i+1]){
		min1=pre[i-1]+suff[i+1];
		z=i;
	    }
	}
	else{
	    if(i==0){
		if(min1>=suff[i+1]){
		min1=suff[i+1];
		z=i;
		}
	    }
	    if(i==pre.size()-1){
		if(min1>=pre[i-1]){
		min1=pre[i-1];
		z=i;
		}
	    }
	}
    }
   // cout<<z<<endl;
   for(ll i=0;i<n;i++){
       if(v[z]==v1[i]){
	z=i;
	break;
       }
   }
   ll temp=v1[z];
   // cout<<min1<<endl;
   ll z1=z;
    for(ll i=z;i>=0;i--){
	if(v1[i]==temp){
	    z=i;
	}
	else{
	    if(v1[i]<temp){
		v1[i]=temp;
		//z=i;
    v2.push_back(make_pair(1, make_pair(i+1, z+1)));
   // cout<<1<<" "<<i+1<<" "<<z+1<<endl;
		z=i;
	    }
	    else if(v1[i]>temp){
		v1[i]=temp;
		//z=i;
		    v2.push_back(make_pair(2, make_pair(i+1, z+1)));

		//cout<<2<<" "<<i+1<<" "<<z+1<<endl;
		z=i;
	    }
	}
    }
    for(ll i=z1;i<n;i++){
	if(v1[i]==temp){
	    z1=i;
	}
	else{
	    if(v1[i]<temp){
		v1[i]=temp;
		    v2.push_back(make_pair(1, make_pair(i+1, z1+1)));

		//cout<<1<<" "<<i+1<<" "<<z+1<<endl;
		z1=i;
	    }
	    else if(v1[i]>temp){
		v1[i]=temp;
		//z=i;
		    v2.push_back(make_pair(2, make_pair(i+1, z1+1)));
		//cout<<2<<" "<<i+1<<" "<<z+1<<endl;
		z1=i;
	    }
	}
    }
        cout<<v2.size()<<endl;
    for(ll i=0;i<v2.size();i++){
	cout<<v2[i].first<<" "<<v2[i].second.first<<" "<<v2[i].second.second<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
using namespace std::chrono;
#define ll long long int
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output1.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    vector<ll>v,pre,suff,te,v1;
    set<ll>s;
    multiset<ll>ms;
    vector< pair<ll, pair<ll,ll> > > v2;
        for(ll i=0,temp,temp1;i<n;i++){
	cin>>temp;
	temp1=s.size();
	s.insert(temp);
	ms.insert(temp);
	v1.push_back(temp);
	if(s.size()!=temp1)
	    v.push_back(temp);
    }
    if(s.size()==1){
	cout<<0<<endl;
	return 0;
    }
    for(auto x:s){
	//cout<<ms.count(x)<<endl;
	te.push_back(ms.count(x));
    }
    pre.push_back(te[0]);
    suff.push_back(te[te.size()-1]);
    for(ll i=1;i<te.size();i++){
	pre.push_back(te[i]+pre[i-1]);
	suff.push_back(te[i]+suff[i-1]);
    }
    reverse(suff.begin(),suff.end());
    ll min1=INT_MAX,z;
    for(ll i=0;i<pre.size();i++){
	if(i!=0&&i!=pre.size()-1){
	    if(min1>=pre[i-1]+suff[i+1]){
		min1=pre[i-1]+suff[i+1];
		z=i;
	    }
	}
	else{
	    if(i==0){
		if(min1>=suff[i+1]){
		min1=suff[i+1];
		z=i;
		}
	    }
	    if(i==pre.size()-1){
		if(min1>=pre[i-1]){
		min1=pre[i-1];
		z=i;
		}
	    }
	}
    }
   // cout<<z<<endl;
   for(ll i=0;i<n;i++){
       if(v[z]==v1[i]){
	z=i;
	break;
       }
   }
   ll temp=v1[z];
   // cout<<min1<<endl;
   ll z1=z;
    for(ll i=z;i>=0;i--){
	if(v1[i]==temp){
	    z=i;
	}
	else{
	    if(v1[i]<temp){
		v1[i]=temp;
		//z=i;
    v2.push_back(make_pair(1, make_pair(i+1, z+1)));
   // cout<<1<<" "<<i+1<<" "<<z+1<<endl;
		z=i;
	    }
	    else if(v1[i]>temp){
		v1[i]=temp;
		//z=i;
		    v2.push_back(make_pair(2, make_pair(i+1, z+1)));

		//cout<<2<<" "<<i+1<<" "<<z+1<<endl;
		z=i;
	    }
	}
    }
    for(ll i=z1+1;i<n;i++){
	if(v1[i]==temp){
	    z1=i;
	}
	else{
	    if(v1[i]<temp){
		v1[i]=temp;
		    v2.push_back(make_pair(1, make_pair(i+1, z1+1)));

		//cout<<1<<" "<<i+1<<" "<<z+1<<endl;
		z1=i;
	    }
	    else if(v1[i]>temp){
		v1[i]=temp;
		//z=i;
		    v2.push_back(make_pair(2, make_pair(i+1, z1+1)));
		//cout<<2<<" "<<i+1<<" "<<z+1<<endl;
		z1=i;
	    }
	}
    }
        cout<<v2.size()<<endl;
    for(ll i=0;i<v2.size();i++){
	cout<<v2[i].first<<" "<<v2[i].second.first<<" "<<v2[i].second.second<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
using namespace std::chrono;
#define ll long long int
ll a[200009];
ll cnt[200009];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output1.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll max=0,pos;
    for(ll i=0;i<n;i++)
    {
	    cin>>a[i];
	    cnt[a[i]]++;
	    if(max<cnt[a[i]])
	    {
		    max=cnt[a[i]];
		    pos=i;
	    }
    }
    ll tar=a[pos];
    cout<<n-max<<endl;
    for(ll i=pos-1;i>=0;i--)
    {
	    if(a[i]!=tar)
		    cout<<1+(a[i]>tar)<<' '<<i+1<<' '<<i+2<<endl;
    }
    for(ll i=pos+1;i<n;i++)
    {
	    if(a[i]!=tar)
		    cout<<1+(a[i]>tar)<<' '<<i+1<<' '<<i<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
using namespace std::chrono;
#define ll long long int
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output1.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    vector<ll>v,pre,suff,te,v1;
    set<ll>s;
    multiset<ll>ms;
    vector< pair<ll, pair<ll,ll> > > v2;
        for(ll i=0,temp,temp1;i<n;i++){
	cin>>temp;
	temp1=s.size();
	s.insert(temp);
	ms.insert(temp);
	v1.push_back(temp);
	if(s.size()!=temp1)
	    v.push_back(temp);
    }
    if(s.size()==1){
	cout<<0<<endl;
	return 0;
    }
    for(auto x:s){
	//cout<<ms.count(x)<<endl;
	te.push_back(ms.count(x));
    }
    pre.push_back(te[0]);
    suff.push_back(te[te.size()-1]);
    for(ll i=1;i<te.size();i++){
	pre.push_back(te[i]+pre[i-1]);
	suff.push_back(te[i]+suff[i-1]);
    }
    reverse(suff.begin(),suff.end());
    ll min1=INT_MAX,z;
    for(ll i=0;i<pre.size();i++){
	if(i!=0&&i!=pre.size()-1){
	    if(min1>=pre[i-1]+suff[i+1]){
		min1=pre[i-1]+suff[i+1];
		z=i;
	    }
	}
	else{
	    if(i==0){
		if(min1>=suff[i+1]){
		min1=suff[i+1];
		z=i;
		}
	    }
	    if(i==pre.size()-1){
		if(min1>=pre[i-1]){
		min1=pre[i-1];
		z=i;
		}
	    }
	}
    }
   // cout<<z<<endl;
   for(ll i=0;i<n;i++){
       if(v[z]==v1[i]){
	z=i;
	break;
       }
   }
   ll temp=v1[z];
   // cout<<min1<<endl;
    for(ll i=z;i>=0;i--){
	if(v1[i]==temp){
	    z=i;
	}
	else{
	    if(v1[i]<temp){
		v1[i]=temp;
		//z=i;
    v2.push_back(make_pair(1, make_pair(i+1, z+1)));
   // cout<<1<<" "<<i+1<<" "<<z+1<<endl;
		z=i;
	    }
	    else if(v1[i]>temp){
		v1[i]=temp;
		//z=i;
		    v2.push_back(make_pair(2, make_pair(i+1, z+1)));

		//cout<<2<<" "<<i+1<<" "<<z+1<<endl;
		z=i;
	    }
	}
    }
    for(ll i=z;i<n;i++){
	if(v1[i]==temp){
	    z=i;
	}
	else{
	    if(v1[i]<temp){
		v1[i]=temp;
		    v2.push_back(make_pair(1, make_pair(i+1, z+1)));

		//cout<<1<<" "<<i+1<<" "<<z+1<<endl;
		z=i;
	    }
	    else if(v1[i]>temp){
		v1[i]=temp;
		//z=i;
		    v2.push_back(make_pair(2, make_pair(i+1, z+1)));
		//cout<<2<<" "<<i+1<<" "<<z+1<<endl;
		z=i;
	    }
	}
    }
        cout<<v2.size()<<endl;
    for(ll i=0;i<v2.size();i++){
	cout<<v2[i].first<<" "<<v2[i].second.first<<" "<<v2[i].second.second<<endl;
    }
    return 0;
}


t = int(input())

for i in range(t):
    nx = list(map(int, input().split()))
    x = nx[1]
    a = list(map(int, input().split()))
    counter1 = 0
    counter2 = -1
    counter3 = 0
    counter4 = 0
    list1 = []
    list2 = []
    while sum(a) % x == 0:
        list1.append(a[counter1])
        counter1 += 1
        counter3 += 1
        if sum(list1) % x != 0:
            break
        if len(list1) == len(a):
            counter3 = len(a) + 1
            break
    while sum(a) % x == 0:
        list2.append(a[counter2])
        counter2 -= 1
        counter4 += 1
        if sum(list2) % x != 0:
            break
        if len(list2) == len(a):
            counter4 = len(a) + 1
            break

    print(max(len(a) - counter3, len(a) - counter4))


# -*- coding: utf-8 -*-
"""
Created on Sun May 31 22:45:01 2020

@author: taolinlin
"""
t = int(input())
for j in range(t):
    n, x = map(int, input().split())
    a = list(map(int, input().split()))
    if sum(a) % x != 0:
        print(n)
    else:
        count = 0
        for i in range(len(a)):
            a[i] = a[i] % x
            if a[i] != 0:
                count += 1
        if count > 0:
            print(n-1)
        else:
            print(-1)


# -*- coding: utf-8 -*-
"""
Created on Sun May 31 22:45:01 2020

@author: taolinlin
"""
t = int(input())
for j in range(t):
    n, x = map(int, input().split())
    a = list(map(int, input().split()))
    b = []
    for i in range(len(a)):
        a[i] = a[i] % x
        if a[i] != 0:
            b.append(i)
    if sum(a) % x != 0:
        print(n)
    elif sum(a) == 0:
        print(-1)
    else:
        print(max(n-b[0]-1, b[-1]))


# -*- coding: utf-8 -*-
"""
Created on Sun May 31 22:45:01 2020

@author: taolinlin
"""
t = int(input())
for j in range(t):
    n, x = map(int, input().split())
    a = list(map(int, input().split()))
    b = []
    for i in range(len(a)):
        a[i] = a[i] % x
        if a[i] != 0:
            b.append(i)
    if sum(a) % x != 0:
        print(n)
    elif sum(a) == 0:
        print(-1)
    else:
        print(max(n-b[0]-1, b[-1]-1))


# -*- coding: utf-8 -*-
"""
Created on Sun May 31 22:45:01 2020

@author: taolinlin
"""
t = int(input())
for j in range(t):
    n, x = map(int, input().split())
    a = list(map(int, input().split()))
    count = 0
    for i in range(len(a)):
        a[i] = a[i] % x
        if a[i] != 0:
            count += 1
    if sum(a) % x != 0:
        print(n)
    else:
        if count > 0:
            print(n-1)
        else:
            print(-1)


t = int(input())

for _ in range(t):
	n,k = map(int, input().split())
	x 	= list(map(int, input().split()))

	if sum(x)%k != 0:
		print(len(x))
		continue

	tot_div = 0
	for i in range(n):
		if x[i]%k == 0:
			tot_div += 1
	if tot_div == n:
		print(-1)
		continue

	total = sum(x)
	mini = -1

	for i in range(n):
		total -= x[i]
		if total%k != 0:
			mini = max(mini,n-i-1)

	total2 = sum(x)
	for i in range(n-1,-1,-1):
		total2 -= x[i]
		if total2%k != 0:
			mini = max(mini,i)

	print(mini)


t = int(input())

for _ in range(t):
	n,k = map(int, input().split())
	x 	= list(map(int, input().split()))

	ct = -1

	if n == 1:
		if x[0]%k != 0:
			print(1)
		else:
			print(-1)
		continue
	for i in range(n-1):
		for j in range(i+1, n):
			if sum(x[i:j+1])%k != 0:
				ct = max(ct,j-i+1)

	print(ct)


t = int(input())

for _ in range(t):
	n,k = map(int, input().split())
	x 	= list(map(int, input().split()))

	ct = -1
	for i in range(n-1):
		for j in range(i+1, n):
			if sum(x[i:j+1])%k != 0:
				ct = max(ct,j-i+1)

	print(ct)


t = int(input())

for _ in range(t):
	n,k = map(int, input().split())
	x 	= list(map(int, input().split()))

	if sum(x)%k != 0:
		print(len(x))
		continue

	tot_div = 0
	for i in range(n):
		if x[i]%k == 0:
			tot_div += 1
	if tot_div == n-1:
		print(-1)
		continue

	total = sum(x)
	mini = -1

	for i in range(n):
		if total%k != 0:
			mini = max(mini,n-i)
		total -= x[i]

	total2 = sum(x)
	for i in range(n-1,-1,-1):
		if total2%k != 0:
			mini = max(mini,i)
		total2 -= x[i]

	print(mini)


t=int(input())
for i in range(t):
    n,x=map(int,input().split())
    a=list(map(int,input().split()))
    l=0
    for i in range(n):
        r,q,k=a[i],i,0
        while r%x!=0:
            q+=1
            if q==n:
                break
            k+=1;r+=a[q]
        l=max(l,k)
    print(l+1 if l!=0 else -1)


I=lambda:map(int,input().split())
for i in range(int(input())):
    n,x=I()
    a=list(I())
    q=sum(a)
    w,t=0,q%x==0
    if q%x==0:
        for i in range(n):
            if a[i]%x:w=i+1;t=0;break
    print(-1if t else max(n-w,w))


I=lambda:map(int,input().split())
for i in range(int(input())):
    n,x=I()
    a=list(I())
    q=sum(a)
    w,t=0,q%x==0
    if q%x==0:
        for i in range(n):
            if a[i]%x or a[n-1-i]%x:w=i+1;t=0;break
    print(-1if t else n-w)


t=int(input())

for _ in range(t):
	n,x=map(int,input().split())
	a=list(map(int,input().split()))
	mx=-1
	for i in range(n):
		su=0
		for j in range(i,n):
			su+=a[j]
			if(su%x!=0):
				if(j-i+1>mx):
					mx=j-i+1
	print(mx)


t=int(input())

for _ in range(t):
	n,x=map(int,input().split())
	a=list(map(int,input().split()))
	mod=[0]*(n)
	ans=-1
	cur=0
	maxlen=-1
	for i in range(n):
		cur+=a[i]
		mod[i]=cur%x
	first_0=-1
	last_0=-1
	for i in range(n):
		if(mod[i]==0):
			first_0=i
			break
	for i in range(n-1,-1,-1):
		if(mod[i]==0):
			last_0=i
			break
	first=-1
	last=-1
	for i in range(n):
		if(mod[i]!=0):
			first=i
			break
	for i in range(n-1,-1,-1):
		if(mod[i]!=0):
			last=i
			maxlen=i+1
			break
	if(first==-1 and last==-1):
		print(-1)
	elif(first_0==-1 and last_0==-1):
		print(n)
	else:
		#print(mod)
		#print(first_0,last_0,first,last)
		if(first!=-1 and first_0!=-1):
			ans=abs(first-first_0)
		if(first!=-1 and last_0!=-1):
			v=abs(first-last_0)
			ans=max(ans,v)
		if(last!=-1 and first_0!=-1):
			w=abs(last-first_0)
			ans=max(ans,w)
		if(last!=-1 and last_0!=-1):
			x=abs(last-last_0)
			ans=max(ans,x)
		print(max(ans,maxlen))


t=int(input())

for _ in range(t):
	n,x=map(int,input().split())
	a=list(map(int,input().split()))
	pre=[0]*(n+1)
	ans=-1
	for i in range(1,n+1):
		pre[i]=pre[i-1]+a[i-1]
	#print(pre)
	for i in range(n):
		for j in range(n,i,-1):
			su=pre[j]-pre[i]
			#print(su)
			if(su%x!=0 and j-i>ans):
				ans=j-i
				break
	print(ans)


t=int(input())

for _ in range(t):
	n,x=map(int,input().split())
	a=list(map(int,input().split()))
	mod=[0]*(n)
	ans=-1
	cur=0
	for i in range(n):
		cur+=a[i]
		mod[i]=cur%x
	first_0=-1
	last_0=-1
	for i in range(n):
		if(mod[i]==0):
			first_0=i
			break
	for i in range(n-1,-1,-1):
		if(mod[i]==0):
			last_0=i
			break
	first=-1
	last=-1
	for i in range(n):
		if(mod[i]!=0):
			first=i
			break
	for i in range(n-1,-1,-1):
		if(mod[i]!=0):
			last=i
			break
	if(first==-1 and last==-1):
		print(-1)
	elif(first_0==-1 and last_0==-1):
		print(n)
	else:
		#print(mod)
		#print(first_0,last_0,first,last)
		if(first!=-1 and first_0!=-1):
			ans=abs(first-first_0)
		if(first!=-1 and last_0!=-1):
			v=abs(first-last_0)
			ans=max(ans,v)
		if(last!=-1 and first_0!=-1):
			w=abs(last-first_0)
			ans=max(ans,w)
		if(last!=-1 and last_0!=-1):
			x=abs(last-last_0)
			ans=max(ans,x)
		print(ans)


t=int(input())

for _ in range(t):
	n,x=map(int,input().split())
	a=list(map(int,input().split()))
	mx=-1
	for i in range(n):
		su=a[i]
		for j in range(i+1,n):
			su+=a[j]
			if(su%x!=0):
				if(j-i+1>mx):
					mx=j-i+1
	print(mx)


import os,io
from sys import stdout
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

t = int(input())
for i in range(t):
    n, x = list(map(int, input().split()))
    l = list(map(int, input().split()))

    mods = [0] * n
    prev = l[0]
    mods[0] = prev % x
    for i in range(1, n):
        mods[i] = (mods[i-1] + l[i]) % x
        prev = prev + l[i]

    first = -1
    for i in range(n):
        if mods[i] != 0:
            first = i

    result = -1
    if first == -1:
        print(-1)
    else:
        m = -1
        for i in range(n):
            if mods[i] != 0:
                m = i + 1
            else:
                m = i - first
            result = max(result, m)
        print(result)


import sys
import collections

t = int(sys.stdin.readline().strip())
for i in range(t):
    n, x = list(map(int,sys.stdin.readline().strip().split(' ')))
    l = list(map(int,sys.stdin.readline().strip().split(' ')))

    best = -1
    c = [0 for i in range(n)]
    c[0] = l[0]
    for i in range(1, n):
        c[i] = l[i] + c[i-1]

    c = [0] + c
    for i in range(0, n+1):
        for j in range(i+1, n+1):
            if (c[j] - c[i]) % x != 0:
                best = max(best, j-i)
    print(best)


import sys
import collections

def sol(c):
    for i in range(n, 0, -1):
        j = 0
        while i + j <= n:
            if (c[i+j] - c[j]) % x != 0:
                return i
            j += 1
    return -1

t = int(sys.stdin.readline().strip())
for i in range(t):
    n, x = list(map(int,sys.stdin.readline().strip().split(' ')))
    l = list(map(int,sys.stdin.readline().strip().split(' ')))

    best = -1
    c = [0 for i in range(n)]
    c[0] = l[0]
    for i in range(1, n):
        c[i] = l[i] + c[i-1]

    c = [0] + c
    print(sol(c))


import sys
import collections

t = int(sys.stdin.readline().strip())
for i in range(t):
    n, x = list(map(int,sys.stdin.readline().strip().split(' ')))
    l = list(map(int,sys.stdin.readline().strip().split(' ')))

    best = -1
    c = [0 for i in range(n)]
    c[0] = l[0]
    for i in range(1, n):
        c[i] = l[i] + c[i-1]

    c = [0] + c
    for i in range(0, n+1):
        if n - i <= best:
            break
        for j in range(n, i, -1):
            if j-i < best:
                break
            if (c[j] - c[i]) % x != 0:
                best = max(best, j-i)
    print(best)


import os,io
from sys import stdout
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

t = int(input())
for i in range(t):
    n, x = list(map(int, input().split()))
    l = list(map(int, input().split()))

    mods = [0] * n
    prev = l[0]
    mods[0] = prev % x
    for i in range(1, n):
        mods[i] = (mods[i-1] + l[i]) % x
        prev = prev + l[i]

    first = -1
    for i in range(n):
        if mods[i] != 0:
            first = i
            break

    result = -1
    if first == -1:
        print(-1)
    else:
        m = -1
        for i in range(first, n):
            if mods[i] != 0:
                m = i + 1
            else:
                m = i - first
            result = max(result, m)
        print(result)


t = int(input())
for cases in range(t):
  s = input()
  x = int(input())
  list1 = [int(item) for item in s.split(' ')]
  count = 0
  L = len(list1)
  for num in list1:
      if num%2==0:
          count = count + 1
  if count!=L:
      while sum(list1)%x == 0:
          if list1[0]%x != 0:
              list1.pop(0)
              break
          elif list1[-1]%x != 0:
              list1.pop()
          else:
              continue
      print(len(list1))
  else:
      print(-1)


t = int(input())
for cases in range(t):
  s1 = input()
  list2 = [int(item) for item in s1.split(' ')]
  x = list2[1]
  s = input()
  list1 = [int(item) for item in s.split(' ')]
  count = 0
  L = len(list1)
  for num in list1:
      if num%2==0:
          count = count + 1
  if count!=L:
      while sum(list1)%x == 0:
          if list1[0]%x != 0:
              list1.pop(0)
              break
          elif list1[-1]%x != 0:
              list1.pop()
          else:
              continue
      print(len(list1))
  else:
      print(-1)


# cook your dish here
t = int(input())
for cases in range(t):
    s = input()
    b = input()
    a = [int(item) for item in b.split(' ')]
    p = [int(item) for item in s.split(' ')]
    k = p[1]
    if sum(a)%k == 0:
        while len(a)>1 and a[0]%k==0 and a[-1]%k==0:
            a.pop(0)
            a.pop()
        if len(a)!=0 and a[0]%k != 0:
            a.pop(0)
        elif len(a)!=0 and a[-1]%k!=0:
            a.pop()
        if len(a)==1:
            if a[0]%k!=0:
                print(len(a))
            else:
                print(-1)
        elif len(a)!=0:
            print(len(a))
        else:
            print(-1)
    else:
        print(p[0])


# cook your dish here
t = int(input())
for cases in range(t):
    s = input()
    b = input()
    a = [int(item) for item in b.split(' ')]
    p = [int(item) for item in s.split(' ')]
    k = p[1]
    n = p[0]
    count = 0
    for item in a:
        if item%k!=0:
            count = 1
            break
    if count ==0:
        print(-1)

    elif sum(a)%k!=0:
        print(n)
    else:
        x1=0
        x2 = 0
        for item in a:
            if item%k != 0:
                x1 = a.index(item)
                break
        a.reverse()
        for item in a:
            if item%k != 0:
                x2 = a.index(item)
                break
        length = max(n-x1-1,n-(x2-0+1))
        print(length)


# cook your dish here
t = int(input())
for cases in range(t):
    s = input()
    b = input()
    a = [int(item) for item in b.split(' ')]
    p = [int(item) for item in s.split(' ')]
    k = p[1]
    if sum(a)%k == 0:
        while len(a)>1 and a[0]%k==0 and a[-1]%k==0:
            if a[-1]==0:
                a.pop(0)
            elif a[0]==0:
                a.pop()
            else:
                a.pop(0)
                a.pop()
        if len(a)!=0 and a[0]%k != 0:
            a.pop(0)
        elif len(a)!=0 and a[-1]%k!=0:
            a.pop()
        if len(a)==1:
            if a[0]%k!=0:
                print(len(a))
            else:
                print(-1)
        elif len(a)!=0:
            print(len(a))
        else:
            print(-1)
    else:
        print(p[0])


for i in range(int(input())):
    n,x=map(int,input().split())
    a=[int(i) for i in input().split()]
    s=sum(a)
    ans=0
    i=0
    j=n-1
    m=1000000
    g=1000000
    if s%x!=0:
        ans=n
        print(ans)
    else:
        for i in range(n):
            if (s-a[i])%x!=0:
                m=i+1
                #print(m)
                break
            else:
                s=s-a[i]
        s=sum(a)
        for j in range(n-1,-1,-1):

            if (s-a[j])%x!=0:
                g=abs(j-n)
                break
            else:
                s=s-a[j]

        if m<n or g<n:
            print(n-min(m,g))
        else:
            print(-1)


for i in range(int(input())):
    n,x=map(int,input().split())
    a=[int(i) for i in input().split()]
    s=sum(a)
    ans=0
    i=0
    j=n-1
    m=1000000
    g=1000000
    if s%x!=0:
        ans=n
        print(ans)
    else:
        for i in range(n):
            if (s-a[i])%x!=0:
                m=i+1
                #print(m)
                break
            else:
                s=s-a[i]
        s=sum(a)
        for j in range(n-1,-1,-1):

            if (s-a[j])%x==0:
                g=abs(j-n)
                break
            else:
                s=s-a[j]

        if m<n or g<n:
            print(n-min(m,g))
        else:
            print(-1)


for i in range(int(input())):
	n,x=map(int,input().split())
	a=[int(i) for i in input().split() ]
	c=0
	for i in a:
		if i%x!=0:
			c+=1
	print(c)


for i in range(int(input())):
    n,x=map(int,input().split())
    a=[int(i) for i in input().split()]
    s=sum(a)
    ans=0
    i=0
    j=n-1
    m=1000000
    g=1000000
    if s%x!=0:
        ans=n
        print(ans)
    else:
        for i in range(n):
            if (s-a[i])%x!=0:
                m=i+1
                #print(m)
                break
            else:
                s=s-a[i]
        s=sum(a)
        for j in range(n-1,-1):
            if (s-a[j])%x==0:
                g=abs(j-n)
                break
            else:
                s=s-a[j]

        if m<n or g<n:
            print(n-min(m,g))
        else:
            print(-1)


for i in range(int(input())):
    n,x=map(int,input().split())
    a=[int(i) for i in input().split()]
    s=sum(a)
    ans=0
    i=0
    j=n-1
    m=1000000
    g=1000000
    if s%x!=0:
        ans=n
        print(ans)
    else:
        for i in range(n):
            if (s-a[i])%x!=0:
                m=i+1
                #print(m)
                break
            else:
                s=s-a[i]
        s=sum(a)
        for j in range(n-1,-1,-1):

            if (s-a[j])%x!=0:
                g=abs(j-n)+1
                break
            else:
                s=s-a[j]

        if m<n or g<n:
            print(n-min(m,g))
        else:
            print(-1)


for _t in range(int(input())):
    n, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    m  = -1
    l = c = s = h = 0
    while h < n:
        s += a[h]
        c += 1
        if s%x != 0:
            m = max(m, c)
        else:
            while s%x == 0 and l < h:
                s -= a[l]
                l += 1
                c -= 1
        h += 1
    if m == -1:
        print(m)
    else:
        print(max(m,c))


for _t in range(int(input())):
    n, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    m  = -1
    c = 0
    s = 0
    for i in a:
        s += i
        if s%x==0:
            if i%x == 0:
                c = 0
                s = 0
            else:
                c = 1
                s = i
        else:
            c += 1
        m = max(c, m)
    if max(m,c) == 0:
        print(-1)
    else:
        print(max(m,c))


for _t in range(int(input())):
    n, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    if sum(a)%x != 0:
        print(n)
    else:
        l = None
        r = None
        for i in range(n):
            if a[i]%x != 0:
                l = i
                break
        for i in range(n-1, -1,-1):
            if a[i]%x != 0:
                r = i
                break
        if l == None:
            print(-1)
        else:
            print(n-min(l+1,n-r))


for _t in range(int(input())):
    n, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    m  = -1
    def chk(arr, l,h):
        if l == h:
            return 0
        if sum(arr[l:h])%x != 0:
            return h-l
        else:
            return max(chk(arr,l,h-1), chk(arr,l+1, h))
    ans = chk(a, 0, n)
    if ans == 0:
        print(-1)
    else:
        print(ans)


for _t in range(int(input())):
    n, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    m  = -1
    l = c = s = h = 0
    while h < n:
        s += a[h]
        c += 1
        if s%x != 0:
            m = max(m, c)
        else:
            while s%x == 0 and l <= h:
                s -= a[l]
                l += 1
                c -= 1
        h += 1
    if m == -1:
        print(m)
    else:
        print(max(m,c))


import os
import sys
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
def get_int(): return int(input())
def get_ints(): return map(int, input().split())
def get_strs(): return input().split()
def get_float(): return float(input())
def get_floats(): return map(float, input().split())
def list_strs(): return list(input().split())
def list_ints(): return list(map(int, input().split()))
def list_floats(): return list(map(float, input.split()))
def post(x): print(x, end=' ')

T = int(input())

for t in range(1, T+1):
    n,x = get_ints()
    a = list_ints()
    res = n if sum(a) % x != 0 else 0
    if res != 0:
        print(res)
    else:
        for i in range(n):
            for j in range(i, n):
                if sum(a[i:j+1]) % x != 0:
                    res = max(res, len(a[i:j+1]))

        print(res if res != 0 else -1)


import os
import sys
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
def get_int(): return int(input())
def get_ints(): return map(int, input().split())
def get_strs(): return input().split()
def get_float(): return float(input())
def get_floats(): return map(float, input().split())
def list_strs(): return list(input().split())
def list_ints(): return list(map(int, input().split()))
def list_floats(): return list(map(float, input.split()))
def post(x): print(x, end=' ')

T = int(input())

for t in range(1, T+1):
    n,x = get_ints()
    a = list_ints()
    res = -1 if all(i % x == 0 for i in a) else 0
    res = n if sum(a) % x != 0 else 0
    l = r = -1
    if res != 0:
        print(res)
    else:
        res = -1
        for i in range(n):
            if a[i] % x != 0 and l == -1:
                l = i
            elif a[i] % x != 0 and l != -1:
                r = i
                res = max(res, r-l+1)
                l = r = -1

        print(res)


import os
import sys
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
def get_int(): return int(input())
def get_ints(): return map(int, input().split())
def get_strs(): return input().split()
def get_float(): return float(input())
def get_floats(): return map(float, input().split())
def list_strs(): return list(input().split())
def list_ints(): return list(map(int, input().split()))
def list_floats(): return list(map(float, input.split()))
def post(x): print(x, end=' ')

j = int(input())

for t in range(1, j+1):
    n,x = get_ints()
    a = list_ints()
    res = -1 if all(i % x == 0 for i in a) else 0
    res = n if sum(a) % x != 0 else 0
    l,r = -1,0
    if res != 0:
        print(res)
    else:
        res = -1
        for i in range(n):
            if a[i] % x != 0 and l == -1:
                l = r = i
            elif a[i] % x != 0:
                r = i

        res = max(n-l-1, r)
        print(res if l != -1 else l)


import os
import sys
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
def get_int(): return int(input())
def get_ints(): return map(int, input().split())
def get_strs(): return input().split()
def get_float(): return float(input())
def get_floats(): return map(float, input().split())
def list_strs(): return list(input().split())
def list_ints(): return list(map(int, input().split()))
def list_floats(): return list(map(float, input.split()))
def post(x): print(x, end=' ')

T = int(input())

for t in range(1, T+1):
    n,x = get_ints()
    a = list_ints()
    res = n if sum(a) % x != 0 else 0
    res = -1 if all(i % x == 0 for i in a) else 0
    if res != 0:
        print(res)
    else:
        for i in range(n):
            for j in range(i, n):
                if sum(a[i:j+1]) % x != 0:
                    res = max(res, len(a[i:j+1]))

        print(res if res != 0 else -1)


import os
import sys
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
def get_int(): return int(input())
def get_ints(): return map(int, input().split())
def get_strs(): return input().split()
def get_float(): return float(input())
def get_floats(): return map(float, input().split())
def list_strs(): return list(input().split())
def list_ints(): return list(map(int, input().split()))
def list_floats(): return list(map(float, input.split()))
def post(x): print(x, end=' ')

j = int(input())

for t in range(1, j+1):
    n,x = get_ints()
    a = list_ints()
    res = -1 if all(i % x == 0 for i in a) else 0
    res = n if sum(a) % x != 0 else 0
    l = r = -1
    if res != 0:
        print(res)
    else:
        res = -1
        for i in range(n):
            if a[i] % x != 0 and l == -1:
                l = i
            elif a[i] % x != 0 and l != -1:
                r = i
                res = max(res, r-l+1)
                l = r = -1

        print(res)


t = int(input())
for _ in range(t):
    n,x = map(int,input().split(" "))
    a = list(map(int,input().split(" ")))
    sup = 0
    sup = sum(a)
    if(sup%x != 0):
        print(n)
    else:
        i = 0
        check = sup
        while sup%x == 0 and i <n:
            if (a[i]%x != 0):
                sup = sup - a[i]
                n = n -1
                break
            else:
                i = i + 1
        if check != sup:
            print(n)
        else:
            print(-1)


t = int(input())
for _ in range(t):
    if 0 == 0:
        pass
    n,x = map(int,input().split(" "))
    a = list(map(int,input().split(" ")))
    if(sum(a)%x != 0):
        print(n)
    else:
        check = []
        sup = a[0]
        ans = 0
        for i in range(1,n):
            if sup%x == 0:
                sup = 0
                check.append(ans)
                ans = 0
                if a[i-1] %x == 0:
                    sup = a[i]
                    ans = 0
                else:
                    sup = a[i] + a[i-1]
                    ans = 1
            else:
                ans = ans + 1
                sup = sup + a[i]
        if sup % x != 0:
            check.append(ans+1)
        else:
            check.append(ans)
        if max(check) == 0:
            print(-1)
        else:
            print(max(check))


t = int(input())
for _ in range(t):
    n,x = map(int,input().split(" "))
    a = list(map(int,input().split(" ")))
    if(sum(a)%x != 0):
        print(n)
    else:
        start = 0
        for i in range(n):
            if a[i]%x != 0:
                start = i + 1
                break
        end = 0
        for i in range(n):
            if a[-i-1]%x != 0:
                end = -i-1
                break
        start = start
        end = -end
        if start == end and start == 0:
            print(-1)
        else:
            ans = min(start,end)
            print(n-ans)


t = int(input())
for _ in range(t):
    n,x = map(int,input().split(" "))
    a = list(map(int,input().split(" ")))
    if(sum(a)%x != 0):
        print(n)
    else:
        check = []
        sup = a[0]
        ans = 0
        for i in range(1,n):
            if sup%x == 0:
                sup = 0
                check.append(ans)
                ans = 0
                if a[i-1] %x == 0:
                    sup = a[i]
                    ans = 0
                else:
                    sup = a[i] + a[i-1]
                    ans = 1
            else:
                ans = ans + 1
                sup = sup + a[i]
        if sup % x != 0:
            check.append(ans+1)
        else:
            check.append(ans)
        if max(check) == 0:
            print(-1)
        else:
            print(max(check))


for _ in range(int(input())):
	n,x = map(int,input().split())

	l = list(map(int,input().split()))
	j = 1
	flag = False
	if sum(l)%x != 0:
		print(n)
	else:
		while(j<n):
			for i in l:
				if (sum(l)-i) % x != 0:
					print(n-j)
					flag = True
					break
				else:
					break
			l.remove(i)
			j += 1

		if flag == False:
			print('-1')


for _ in range(int(input())):
	n,x = map(int,input().split())

	l = list(map(int,input().split()))
	flag = False
	if sum(l)%x != 0:
		print(n)
	else:
		for i in range(1,n):
			if sum(l[i:]) % x != 0 and flag == False:
				print(n-i)
				flag = True
				break

		if flag == False:
			print('-1')


for _ in range(int(input())):
	n,x = map(int,input().split())

	l = list(map(int,input().split()))
	j = 1
	flag = False
	if sum(l)%x != 0:
		print(n)
	else:
		while(j<n):
			for i in l:
				if (sum(l)-i) % x != 0 and flag == False:
					print(n-j)
					flag = True
					break
			l.remove(min(l))
			j += 1

		if flag == False:
			print('-1')


for _ in range(int(input())):
	n,x = map(int,input().split())

	l = list(map(int,input().split()))
	flag = False
	if sum(l)%x != 0:
		print(n)
	else:
		for i in range(1,n):
			if sum(l[i:]) % x != 0:
				print(n-i)
				flag = True
				break

		if flag == False:
			print('-1')


for _ in range(int(input())):
	n,x = map(int,input().split())
	l = list(map(int,input().split()))
	flag = False
	if sum(l)%x != 0:
		print(n)
	else:
		for i in range(n//2):
			if l[i]%x != 0 or l[n-i-1]%x != 0:
				flag = True
				break

		if flag == False:
			print('-1')
		else:
			print(n-i-1)


for _ in range(int(input())):
	n,x = map(int,input().split())

	l = list(map(int,input().split()))
	j = 1
	flag = False
	if sum(l)%x != 0:
		print(n)
	else:
		while(j<n):
			for i in l:
				if (sum(l)-i) % x != 0 and flag == False:
					print(n-j)
					flag = True
					break
			l.remove(i)
			j += 1

		if flag == False:
			print('-1')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)
def rec(A,i,j,s):
    if(i==j):
        if(s%x):
            return 1
        return -1
    if(s%x):
        return j-i+1
    if((s-A[i])%x!=0):
        return j-i
    if s-A[j]!=0:
        return j-i
    return max(rec(A,i+1,j,s-A[i]),rec(A,i,j-1,s-A[j]))
for _ in range(l()[0]):
    n,x=l()
    A=tuple(l())
    s=sum(A)
    ans=rec(A,0,n-1,s)
    print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

for _ in range(l()[0]):
    n,x=l()
    A=l()
    s=sum(A)
    if s%x:
        print(n)
        continue
    i=0
    j=n-1
    while(i<n and A[i]%x==0):
        i+=1
    i+=1
    while(j>=0 and A[j]%x==0):
        j-=1

    ans=max(n-i,j)
    if(ans==0):
        ans=-1
    print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)
def rec(A,i,j,s):
    # print(A,i,j,s)
    if(i==j):
        if(s%x):
            return 1
        return -1
    if(s%x):
        # print("HERE1")
        return j-i+1
    if((s-A[i])%x!=0):
        # print("HERE2")
        return j-i
    if (s-A[j])%x!=0:
        # print(s-A[j],x,)
        # print("HERE3")
        return j-i
    return max(rec(A,i+1,j,s-A[i]),rec(A,i,j-1,s-A[j]))
for _ in range(l()[0]):
    n,x=l()
    A=tuple(l())
    s=sum(A)
    ans=rec(A,0,n-1,s)
    print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)
def rec(A,i,j,s):
    if(i>j or j<0 or i>=len(A)):
        return -1
    # print(A,i,j,s)
    if(i==j):
        if(s%x):
            return 1
        return -1
    if(s%x):
        # print("HERE1")
        return j-i+1
    if((s-A[i])%x!=0):
        # print("HERE2")
        return j-i
    if (s-A[j])%x!=0:
        # print(s-A[j],x,)
        # print("HERE3")
        return j-i
    return max(rec(A,i+1,j,s-A[i]),rec(A,i,j-1,s-A[j]))
for _ in range(l()[0]):
    n,x=l()
    A=tuple(l())
    s=sum(A)
    ans=rec(A,0,n-1,s)
    print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

for _ in range(l()[0]):
    @lru_cache(None)
    def rec(i,j,s):
        if(i>j):
            return -1
        if(i==j):
            if(s%x):
                return 1
            return -1
        if(s%x):
            return j-i+1
        if((s-A[i])%x!=0):
            return j-i
        if (s-A[j])%x!=0:
            return j-i
        return max(rec(i+1,j,s-A[i]),rec(i,j-1,s-A[j]))
    n,x=l()
    A=l()
    s=sum(A)
    ans=rec(0,n-1,s)
    print(ans)


def solve(arr,n,x):
    sm = sum(arr)
    if sm%x!=0:
        return n
    count = 0
    for i in arr:
        if i%x == 0:
            count += 1
    if count == x:
        return -1
    total = sm
    mx = 0
    for i in range(n):
        sm = sm- arr[i]
        if sm%x!=0:
            break
    mx = max(mx,n-i-1)
    ln = 0
    for i in range(n-1,-1,-1):
        ln += 1
        total = total - arr[i]
        if total%x!=0:
            break
    mx = max(mx,n -ln)
    if mx ==0:
        reutrn -1
    return mx

t = int(input())
for _ in range(t):
    n,x = map(int,input().split())
    arr = list(map(int,input().split()))
    print(solve(arr,n,x))


def solve(arr,n,x):
    sm = sum(arr)
    if sm%x!=0:
        return n
    count = 0
    for i in arr:
        if i%x == 0:
            count += 1
    if count == x:
        return -1
    total = sm
    mx = 0
    for i in range(n):
        sm = sm- arr[i]
        if sm%x!=0:
            break
    mx = max(mx,n-i-1)
    ln = 0
    for i in range(n-1,-1,-1):
        ln += 1
        total = total - arr[i]
        if total%x!=0:
            break
    mx = max(mx,n -ln)
    if mx ==0:
        return -1
    return mx

t = int(input())
for _ in range(t):
    n,x = map(int,input().split())
    arr = list(map(int,input().split()))
    print(solve(arr,n,x))


def solve(arr,n,x):
    sm = sum(arr)
    if sm%x!=0:
        return n
    count = 0
    for i in arr:
        if i%x == 0:
            count += 1
    if count == x:
        return -1
    total = sm
    mx = 0
    for i in range(n):
        sm = sm- arr[i]
        if sm%x!=0:
            break
    mx = max(mx,n-i-1)
    ln = 0
    for i in range(n-1,-1,-1):
        ln += 1
        total = total - arr[i]
        if total%x!=0:
            break
    mx = max(mx,n -ln)
    return mx

t = int(input())
for _ in range(t):
    n,x = map(int,input().split())
    arr = list(map(int,input().split()))
    print(solve(arr,n,x))


t = int(input())
for _ in range(t):
    n,x = map(int,input().split())
    arr = list(map(int,input().split()))
    #print(arr)
    pre = 0
    prefix = [0 for i in range(n)]
    for i in range(n):
        prefix[i] = arr[i] + pre
        pre = prefix[i]
    mx = -1
    for i in range(n):
        for j in range(i,n):
            if i == 0 and prefix[j]%x!=0:
                mx = max(mx,j+1)
            else:
                if (prefix[j]-prefix[i])%x!=0:
                    #print("i",i,"j",j,"prefix[i]",prefix[i],"prefix[j]",prefix[j],"mx",mx)
                    mx = max(mx,j-i)
    print(mx)


def solve(n, x, l):
    i = 0
    j = 0
    ans = -1
    s = 0
    for i in range(n):
        for j in range(i, n):
            s+=l[j]
            if s%x!=0 and ans < j - i + 1:
                ans = j - i + 1
        s = 0
    return ans

t = int(input())
for we in range(t):
    n, x = map(int, input().split())
    l = list(map(int, input().split()))
    print(solve(n, x, l))


def solve(n, x, l):
    i = 0
    j = 0
    ans = -1
    s = sum(l)
    for i in range(n):
        for j in range(n-1, i-1, -1):
            s -= l[j]
            if s%x!=0 and ans < j - i + 1:
                ans = j - i + 1
                break
        s -= l[i]
    return ans

t = int(input())
for we in range(t):
    n, x = map(int, input().split())
    l = list(map(int, input().split()))
    print(solve(n, x, l))