#include<bits/stdc++.h>
using namespace std;
inline int read(){
int ret=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-f;for(;isdigit(ch);ch=getchar())ret=(ret<<1)+(ret<<3)+(ch&15);return ret*f;
}
#define maxn 100005
struct AC{
	int x,y;
}a[maxn];
struct w{
	int op,x,y;
}ans[4000005];
int cnt,p[2000005];
void init(){
	cnt=0;
	int n=read(),m=read(),k=read();//n stuck m pai k kinds
for(int i=1;i<=n;i++)a[i].x=a[i].y=0;
	while(m--){
		int x=read();
		for(int i=1;i<=n;i++){
			if(a[i].x==x){if(!a[i].y)ans[++cnt]=(w){1,i,0};else {ans[++cnt]=(w){1,n,0},ans[++cnt]=(w){2,n,i};}
				a[i].x=a[i].y,a[i].y=0;goto loop;
			}else if(a[i].y==x){ans[++cnt]=(w){1,i,0};a[i].y=0;goto loop;
			}
		}
		for(int i=1;i<n;i++)if(!a[i].x){a[i].x=x,ans[++cnt]=(w){1,i,0};break;}else if(!a[i].y){ans[++cnt]=(w){1,i,0},a[i].y=x;break;}loop:;
	}printf("%d\n",cnt);
	for(int i=1;i<=cnt;i++)if(ans[i].op==2)printf("2 %d %d\n",ans[i].y,ans[i].x);else printf("1 %d\n",ans[i].x);
}
int now;
void init1(){cnt=0;int n=read(),m=read(),k=read();//n stuck m pai k kinds
for(int i=1;i<=m;i++)p[i]=read();p[m+1]=0;
for(int i=1;i<=n;i++)a[i].x=a[i].y=0;
	for(int www=1;www<=m;www++){
		int x=p[www];int id=-1;	int hou=p[1+www];
		for(int i=1;i<n;i++){
			if(a[i].x==x){if(!a[i].y)ans[++cnt]=(w){1,i,0};else {ans[++cnt]=(w){1,n,0},ans[++cnt]=(w){2,n,i};}
				a[i].x=a[i].y,a[i].y=0;goto loop1;
			}else if(a[i].y==x){ans[++cnt]=(w){1,i,0};a[i].y=0;goto loop1;}
		}
		for(int i=1;i<n;i++)if(!a[i].x){a[i].x=x,ans[++cnt]=(w){1,i,0};goto loop1;}else if(!a[i].y){ans[++cnt]=(w){1,i,0},a[i].y=x;goto loop1;}//cant find
	if(hou==x){
			ans[++cnt]=(w){1,n,0};ans[++cnt]=(w){1,n,0};www++;goto loop1;
		}
		for(int i=1;i<=n;i++)if(a[i].x==hou){id=i;break;}
		if(id !=-1){ans[++cnt]=(w){1,id,0};
		ans[++cnt]=(w){1,n,0};
		ans[++cnt]=(w){2,n,id};a[id].x=a[id].y,a[id].y=x;
			www++;goto loop1;
		}for(int i=1;i<=n;i++)if(a[i].y==hou){id=i;break;}ans[++cnt]=(w){1,id,0};a[id].y=0;
		loop1:;
	}printf("%d\n",cnt);
	for(int i=1;i<=cnt;i++)if(ans[i].op==2)printf("2 %d %d\n",ans[i].x,ans[i].y);else printf("1 %d\n",ans[i].x);
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T=read();
	if((T%10)==1)while(T--)init();else while(T--)init1();
	return 0;
} 