#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*f;
}
const int N=2000010;
int T,n,m,K,a[N],s[N][3],t[N],num,b[N],p[N],v[N],flg,res,l[N];
struct rec{int x,y,z;}ans[N];
void work1(){
	num=0;
	for(int i=1;i<=n;i++)t[i]=0;
	for(int i=1,x;i<=m;i++){
		x=(a[i]+1)/2;
		if(!t[x])
			s[x][++t[x]]=a[i],
			ans[++num].x=1,ans[num].y=x;
		else if(s[x][t[x]]==a[i])
			t[x]--,ans[++num].x=1,ans[num].y=x;
		else if(t[x]==1&&s[x][t[x]]!=a[i])
			s[x][++t[x]]=a[i],
			ans[++num].x=1,ans[num].y=x;
		else
			s[x][t[x]-1]=s[x][t[x]],t[x]--,
			ans[++num].x=1,ans[num].y=n,
			ans[++num].x=2,ans[num].y=x,ans[num].z=n;
	}
	printf("%d\n",num);
	for(int i=1;i<=num;i++)
		if(ans[i].x==1)printf("%d %d\n",ans[i].x,ans[i].y);
		else printf("%d %d %d\n",ans[i].x,ans[i].y,ans[i].z);
}
void work2(){
	num=0;
	for(int i=1;i<=n;i++)t[i]=l[i]=0;
	for(int i=1;i<=m;i++){
		if(l[1]==t[1]){
			s[1][++t[1]]=a[i],
			ans[++num].x=1,ans[num].y=1;
			if(!l[1])l[1]=1;
		}
		else if(s[1][l[1]]==a[i])
			l[1]++,ans[++num].x=1,ans[num].y=2,
			ans[++num].x=2,ans[num].y=1,ans[num].z=1;
		else
			s[1][++t[1]]=a[i],
			ans[++num].x=1,ans[num].y=1;
	}
	printf("%d\n",num);
	for(int i=1;i<=num;i++)
		if(ans[i].x==1)printf("%d %d\n",ans[i].x,ans[i].y);
		else printf("%d %d %d\n",ans[i].x,ans[i].y,ans[i].z);
}
void dfs(int x){
	if(flg==1)return;
	if(x==m&&!res){flg=1;return;}
	if(x>m)return;
	for(int i=1;i<=n;i++){
		ans[++num].x=1,ans[num].y=i;
		if(s[i][t[i]]==a[x])
			t[i]--,res-=2,dfs(x+1),num--;
		else if(t[i]<l[i]){
			int tag=0;
			for(int j=1;j<=n;j++){
				if(i==j)continue;
				if(t[j]>=l[j]&&s[j][l[j]]==a[x])
					ans[++num].x=2,ans[num].y=i,ans[num].z=j,
					t[j]--,res-=2,dfs(x+1),num--,tag=1;
				if(flg)return;
			}
			if(flg)return;
			if(!tag)dfs(x+1),num--;else num--;
			if(flg)return;
		}
		else dfs(x+1),num--;
		if(flg)return;
	}
}
void work3(){
	for(int i=1;i<=n;i++)t[i]=1,l[i]=0;
	flg=0,res=m,num=0,dfs(0);
	printf("%d\n",num);
	for(int i=1;i<=num;i++)
		if(ans[i].x==1)printf("%d %d\n",ans[i].x,ans[i].y);
		else printf("%d %d %d\n",ans[i].x,ans[i].y,ans[i].z);
}
void work4(){for(int i=1;i<=n;i++)t[i]=1,l[i]=0;}
void work5(){for(int i=1;i<=n;i++)t[i]=1,l[i]=0;}
void work(int x){
	n=read(),m=read(),K=read();
	for(int i=1;i<=m;i++)a[i]=read();
	if(x%10==1)work1();
	else if(x%10==2)work2();
	else if(x%10==3)work3();
	else if(x%10==4)work4();
	else work5();
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	for(int _=1;_<=T;_++)work(T);
	return 0;
}