#include<bits/stdc++.h>
using namespace std;
#define gc getchar
#define pc putchar
int read(){
	int ret=0;bool f=1;char c=gc();
	while(!isdigit(c))(c=='-'?f=!f:0),c=gc();
	while(isdigit(c))ret=(ret<<3)+(ret<<1)+(c^48),c=gc();
	return f?ret:-ret;
}
const int maxn=305,maxm=2e6+5,maxk=605;
int T,n,m,k,a[maxm],op;
int lnk[maxk],L[maxm],R[maxm];
int nxt[maxm];
int b[maxm],id[maxm],t;
void check(int i,int j){for(;a[i]==a[j]&&i&&j<=m;i--,j++)nxt[i]=j+1,op+=2;}
int s[3][maxm],l[3],r[3];
struct node{
	int x,y,z;
}ans[maxm<<1];
void dfs(int p){
	if(p>n){
		if(l[0]>r[0]&&l[1]>r[1]&&l[2]>r[2]){
			for(int i=1;i<=op;i++){
				printf("%d ",ans[i].x);
				if(ans[i].x==1)printf("%d\n",ans[i].y);
				else printf("%d %d\n",ans[i].y,ans[i].z);
			}
			exit(0);
		}
		return;
	}
	for(int i=0;i<3;i++){
		ans[++op]=(node){1,i+1,0};
		if(l[i]>r[i]){
			bool flg=1;
			for(int j=0;j<3;j++)if(i!=j){
				if(a[p]==s[j][r[j]]){
					int ret=s[j][r[j]];r[j]--;
					ans[++op]=(node){2,i+1,j+1};
					dfs(p+1);
					op--;s[j][++r[j]]=ret;
					flg=0;
				}
			}
			if(flg)s[i][++r[i]]=a[p],dfs(p+1),r[i]--;
		}else{
			if(s[i][r[i]]==a[p])r[i]--,dfs(p+1),s[i][++r[i]]=a[p];
			else s[i][++r[i]]=a[p],dfs(p+1),r[i]--;
		}
		op--;
	}
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	while(T--){
		n=read(),m=read(),k=read();op=0;
		for(int i=1;i<=m;i++)a[i]=read(),nxt[i]=i+1;
		if(T%10==2){
			memset(s[0],0,sizeof s[0]);l[0]=r[0]=1;
			s[0][1]=a[1];ans[++op]=(node){1,1,0};
			for(int i=2;i<=m;i++){
				if(a[i]==s[0][r[0]])ans[++op]=(node){1,1,0},r[0]--;else
				if(a[i]==s[0][l[0]])ans[++op]=(node){1,2,0},ans[++op]=(node){2,1,2},l[0]++;else
				ans[++op]=(node){1,1,0},s[0][++r[0]]=a[i];
			}
			printf("%d\n",op);
			for(int i=1;i<=op;i++){
				printf("%d ",ans[i].x);
				if(ans[i].x==1)printf("%d\n",ans[i].y);
				else printf("%d %d\n",ans[i].y,ans[i].z);
			}
			continue;
		}
		if(T%10==3||T%10==4){
			memset(s,0,sizeof s);
			dfs(1);
			continue;
		}
//		for(int i=1;i<=m;i=nxt[i])b[++t]=a[i],id[t]=i;
//		for(int i=1;i<=m;i=nxt[i]){
//			if(nxt[i]>i+1){
//				for(int j=i;j<nxt[i];j++)printf("1 1\n");
//			}else{
//				
//			}
//		}
	}
	return 0;
}