#include<bits/stdc++.h>
#define SZ(x) ((int)((x).size()))
template<typename _Tp>void read(_Tp &x){
	char ch(getchar());bool f=0;while(!isdigit(ch))f|=ch=='-',ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
	if(f)x=-x;
}
const int N=2000005,MAXN=305;
int a[N],d[MAXN*2],b[MAXN],c[MAXN];bool is[MAXN*2];
std::vector<int> vec[MAXN];
struct node{int x,y,z;}ans[N*2];int pos;
int gettop(int x){return c[x]?c[x]:b[x];}
int getbot(int x){return b[x]?b[x]:c[x];}
void push(int x,int y){
	if(!vec[x].empty()&&vec[x].back()==y)vec[x].pop_back();
	else vec[x].push_back(y);
	b[x]=SZ(vec[x])==0?0:vec[x][0],c[x]=SZ(vec[x])<=1?0:vec[x][1];
	ans[++pos]={1,x,0};
}
void apply(int x,int y){
	vec[x].erase(vec[x].begin()),vec[y].erase(vec[y].begin());
	b[x]=SZ(vec[x])==0?0:vec[x][0],c[x]=SZ(vec[x])<=1?0:vec[x][1];
	b[y]=SZ(vec[y])==0?0:vec[y][0],c[y]=SZ(vec[y])<=1?0:vec[y][1];
	ans[++pos]={2,x,y};
}
void MAIN(){
	int n,m,k;read(n),read(m),read(k);
	for(int i=1;i<=m;++i)read(a[i]);
	for(int i=1;i<=n;++i)b[i]=c[i]=0,vec[i].clear();
	int id=n;pos=0;
	for(int i=1;i<=m;++i){
		bool flag=0;
		for(int j=1;j<=n;++j)if(j!=id){
			if(gettop(j)==a[i])push(j,a[i]),flag=1;
			else if(getbot(j)==a[i])push(id,a[i]),apply(id,j),flag=1;
			if(flag)break;
		}
		if(!flag){
			for(int j=1;j<=n;++j)if(j!=id&&c[j]==0){push(j,a[i]),flag=1;break;}
		}
		if(flag)continue;
		memset(is,0,sizeof(is));
		for(int j=1;j<=n;++j)is[b[j]]=1;
		for(int p=1;p<=n;++p)d[c[p]]=p;
		for(int j=i+1;j<=m;++j){
			if(a[j]==a[i]){
				push(id,a[i]);
				for(int k=i+1;k<j;++k)push(d[a[k]],a[k]);
				push(id,a[j]);i=j;break;
			}
			else if(is[a[j]]){
				int pp=-1;for(int k=1;k<=n;++k)if(b[k]==a[j]){pp=k;break;}
				int tmp=c[pp],fir=-1;for(int k=i+1;k<=j;++k)if(a[k]==c[pp]){fir=k;break;}
				if(fir==-1){
					push(pp,a[i]);
					for(int k=i+1;k<j;++k)push(d[a[k]],a[k]);
					push(id,a[j]),apply(id,pp);
				}
				else{
					push(id,a[i]);
					for(int k=i+1;k<j;++k){
						if(k==fir)push(pp,a[k]);
						else if(a[k]==tmp)push(id,a[k]);
						else push(d[a[k]],a[k]);
					}
					push(pp,a[j]),id=pp;
				}
				i=j;break;
			}
		}
	}
	printf("%d\n",pos);
	for(int i=1;i<=pos;++i){
		if(ans[i].x==1)printf("1 %d\n",ans[i].y);
		else printf("2 %d %d\n",ans[i].y,ans[i].z);
	}
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int _;read(_);
	while(_--)MAIN();
	return 0;
}
