#include<bits/stdc++.h>
using namespace std;
const int N=2e6+5,INF=0x3f3f3f3f;
int path[N],x[N],y[N],cnt,val[N],yin[N],dyin[N];
int n,m,k,sw[N],xw[N],fen[N],fv[N];bool vis[N];
void work()
{
	scanf("%d%d%d",&n,&m,&k);cnt=0;int ls=n-1,lx=0;
	memset(yin,0,sizeof yin);memset(dyin,0,sizeof dyin);
	for(int i=1;i<=n-1;i++) sw[i]=i;
	for(int i=1;i<=m;i++){
		scanf("%d",&val[i]);
		
	}
	for(int i=1;i<=m;i++){
		if(yin[val[i]]==0){
			if(ls){
				path[++cnt]=1;x[cnt]=sw[ls];
				yin[val[i]]=sw[ls];dyin[sw[ls]]=val[i];
				xw[++lx]=sw[ls]+n;ls--;
			}else{
				path[++cnt]=1;x[cnt]=xw[lx]-n;
				yin[val[i]]=xw[lx],dyin[xw[lx]]=val[i],lx--;
			}
		}else{
			if(yin[val[i]]<=n){
				path[++cnt]=1;x[cnt]=n;
				path[++cnt]=2;x[cnt]=yin[val[i]];y[cnt]=n;
				if(dyin[yin[val[i]]+n]){
					int k=dyin[yin[val[i]]+n];
					xw[++lx]=yin[val[i]]+n;
					yin[k]=yin[val[i]];dyin[yin[val[i]]]=k;
					dyin[yin[val[i]]+n]=0;
				}else sw[++ls]=yin[val[i]];
			}else{
				path[++cnt]=1;x[cnt]=yin[val[i]]-n;
				xw[++lx]=yin[val[i]];
				dyin[yin[val[i]]]=0;yin[val[i]]=0;
			}
		}
	}
	cout<<cnt<<endl;
	for(int i=1;i<=cnt;i++){
		printf("%d %d",path[i],x[i]);
		if(path[i]==2) printf(" %d\n",y[i]);
		else puts("");
	}
	return;
}
void work2()
{
	scanf("%d%d%d",&n,&m,&k);cnt=0;int ls=n,lx=0;int duan=0;
	memset(yin,0,sizeof yin);memset(dyin,0,sizeof dyin);
	int num=0;
	for(int i=1;i<=m;i++){
		scanf("%d",&val[i]);
		if(vis[val[i]]){
			if(num==2*n-1) fen[++duan]=i;
			num--;vis[val[i]]=0;
		}else num++,vis[val[i]]=1;
	}for(int i=1;i<=n;i++) sw[i]=i;
	int now=1;
	for(int i=1;i<=m;i++){
		if(i==fen[now]&&now<=duan){
			path[++cnt]=1,x[cnt]=yin[val[i]];
			sw[++ls]=yin[val[i]];now++;continue;
		}
		if(yin[val[i]]==0){
			if(ls){
				path[++cnt]=1;x[cnt]=sw[ls];
				yin[val[i]]=sw[ls];dyin[sw[ls]]=val[i];
				if(now<=duan&&val[i]==val[fen[now]]) continue;
				xw[++lx]=sw[ls]+n;ls--;
			}else{
				path[++cnt]=1;x[cnt]=xw[lx]-n;
				yin[val[i]]=xw[lx],dyin[xw[lx]]=val[i],lx--;
			}
		}else{
			if(yin[val[i]]<=n){
				path[++cnt]=1;x[cnt]=n;
				path[++cnt]=2;x[cnt]=yin[val[i]];y[cnt]=n;
				if(dyin[yin[val[i]]+n]){
					int k=dyin[yin[val[i]]+n];
					xw[++lx]=yin[val[i]]+n;
					yin[k]=yin[val[i]];dyin[yin[val[i]]]=k;
					dyin[yin[val[i]]+n]=0;
				}else sw[++ls]=yin[val[i]];
			}else{
				path[++cnt]=1;x[cnt]=yin[val[i]]-n;
				xw[++lx]=yin[val[i]];
				dyin[yin[val[i]]]=0;yin[val[i]]=0;
			}
		}
	}
	cout<<cnt<<endl;
	for(int i=1;i<=cnt;i++){
		printf("%d %d",path[i],x[i]);
		if(path[i]==2) printf(" %d\n",y[i]);
		else puts("");
	}
	return;
}
int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int t;cin>>t;int p=t;
	while(t--){
		if(p%10==1)
		work();
		else work2();
	}
	return 0;
}