#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
	char c=getchar();int x=0,f=1;
	for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 4000005
#define inf 0x3f3f3f3f
#define ull unsigned long long

int T,O;

int op[maxn],opx[maxn],opy[maxn],tot;

int n,m,k,a[maxn],qwq;
int id;
vi s[1003];
vi vec[1003];

void op1(int u){
//	cout<<"op1 "<<u<<"\n";
	op[++tot]=1;
	opx[tot]=u;
	++qwq;
	if(s[u].size() && s[u].back()==a[qwq])s[u].pop_back();
	else s[u].pb(a[qwq]);
	vec[a[qwq]].pop_back();
}
void op2(int u,int v){
//	cout<<"op2 "<<u<<" "<<v<<"\n";
	op[++tot]=2;
	opx[tot]=u,opy[tot]=v;
	assert(s[u][0]==s[v][0]);
	For(i,0,(int)s[u].size()-2) s[u][i]=s[u][i+1]; s[u].pop_back();
	For(i,0,(int)s[v].size()-2) s[v][i]=s[v][i+1]; s[v].pop_back();
}

int pos[maxn];

void brute(){
	for(int l=1;l<=n;){
		int r=l+1;
		while(a[r]!=a[l])++r;
		
		l=r+1;
	}
}

void work()
{
	n=read(),m=read(),k=read(); qwq=0;
	For(i,1,m)a[i]=read();
	Rep(i,m,1)vec[a[i]].pb(i);
	
	id=n; tot=0;
	For(i,1,m){
		bool ok=0;
	//	cout<<"a[i] "<<a[i]<<"\n";
		For(j,1,n){
			if(j==id||!s[j].size())continue;
	//		cout<<"j: "<<s[j][0]<<" "<<s[j].back()<<"\n";
			if(s[j].size() && s[j][0]==a[i]){
				op1(id);
				op2(id,j);
				ok=1;break;
			}
			if(s[j].size() && s[j].back()==a[i]){
				op1(j);
				ok=1;break;
			}
		}
		if(ok)continue;
	//	cout<<"fail "<<i<<" "<<a[i]<<"\n";
		For(j,1,n){
			if(j==id)continue;
			if(s[j].size()<2){
				op1(j);
				ok=1;break;
			}
		}
		if(ok)continue;
		
		int nd=-1;
		For(j,1,n){
			if(j==id)continue;
			int cnt=0;
			int u=s[j][0],v=s[j][1];
			pos[v]=j;
			pos[u]=-j;
			while(cnt<vec[v].size() && vec[v][vec[v].size()-1-cnt]<vec[u].back()) ++cnt;
			if(!ok && cnt%2==0){
				ok=1;
				nd=u;
				pos[a[i]]=j;
				op1(j);
		//		puts("QAQ");
			}
		}
		if(ok){
			int r=i+1;
		//	cout<<"r: "<<r<<"\n";
			while(r<=m){
				int u=a[r];
				++r;
		//		cout<<"u: "<<u<<" "<<pos[u]<<"\n";
				if(pos[u]>0) op1(pos[u]);
				else op1(id),op2(-pos[u],id);
				if(u==nd)break;
			}
			i=r-1;
		//	puts("done.");
			continue;
		}
		
		op1(id);
		pos[a[i]]=id;
		int r=i+1;
		while(r<=m){
			int u=a[r];
			++r;
			if(pos[u]>0) op1(pos[u]);
			else {
				op1(-pos[u]);
				assert(s[-pos[u]].empty());
				id=-pos[u];
				break;
			}
		}
		i=r-1;
		continue;
	}
	For(i,0,n)assert(s[i].size()==0);
	assert(qwq==m);
	printf("%d\n",tot);
	For(i,1,tot){
		if(op[i]==1) printf("1 %d\n",opx[i]);
		else printf("2 %d %d\n",opx[i],opy[i]);
	}
}

signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	while(T--)work();
	return 0;
}
/*
114
3 8 3
1 2 3 2 2 1 2 3

114
2 4 2
1 2 1 2
3 6 3
*/
