#include<bits/stdc++.h>
using namespace std;
int read(){
	int res=0;
	char x;
	x=getchar();
	while(x<'0'||x>'9'){
		x=getchar();
	}
	while(x>='0'&&x<='9'){
		res=res*10+x-'0';
		x=getchar();
	}
	return res;
}
int T;
int n,m,k;
int q[2000005];
int a[305][60005];
int haed[305],tail[305];
struct da{
	int op;
	int x,y;
}op[4000005];
int tot=0;
int bo[605];
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	while(T--){
		memset(q,0,sizeof(q));
		memset(a,0,sizeof(a));
		memset(haed,0,sizeof(haed));
		memset(tail,0,sizeof(tail));
		tot=0;
		n=read();
		m=read();
		k=read();
		for(int i=1;i<=m;i++){
			q[i]=read();
		}
		for(int i=1;i<n;i++)tail[i]=1;
		for(int i=1;i<=m;i++){
			int done=0;
			for(int j=1;j<n;j++){
				if(a[j][haed[j]]==q[i]&&tail[j]<=haed[j]){
					tot++;
					op[tot].op=1;
					op[tot].x=j;
					a[j][haed[j]]=0;
					haed[j]--;
					done=1;
					break;
				}
				if(a[j][tail[j]]==q[i]&&tail[j]<=haed[j]){
					tot++;
					op[tot].op=1;
					op[tot].x=n;
					tot++;
					op[tot].op=2;
					op[tot].x=j;
					op[tot].y=n;
					done=1;
					a[j][tail[j]]=0;
					tail[j]++;
					break;
				}
			}
			if(done)continue;
			int wz=i%(n-1)+1;
			memset(bo,0,sizeof(bo));
			for(int j=1;j<n;j++){
				bo[a[j][tail[j]]]++;
			}
			for(int j=1;j<n;j++){
				if(bo[a[j][haed[j]]]&&(haed[j]!=tail[j])){
					wz=j;
					break;
				}
				bo[a[j][haed[j]]]++;
			}
			tot++;
			op[tot].op=1;
			op[tot].x=wz;
			haed[wz]++;
			a[wz][haed[wz]]=q[i];
		}
		int done=1;
		while(done){
			done=0;
			for(int i=1;i<n;i++){
				if(tail[i]<=haed[i])done=1;
			}
			if(!done)break;
			for(int i=1;i<n;i++){
				if(tail[i]>haed[i])continue;
				for(int j=i+1;j<n;j++){
					if(tail[j]>haed[j])continue;
					if(a[i][tail[i]]==a[j][tail[j]]){
						tot++;
						op[tot].op=2;
						op[tot].x=i;
						op[tot].y=j;
						tail[i]++;
						tail[j]++;
					}
				}
			}
		}
		printf("%d\n",tot);
		for(int i=1;i<=tot;i++){
			if(op[i].op==1){
				printf("%d %d\n",op[i].op,op[i].x);
			}
			else{
				printf("%d %d %d\n",op[i].op,op[i].x,op[i].y);
			}
		}
	}
	return 0;
}