#include<bits/stdc++.h>
#define maxn 2000005
#define maxl 605
using namespace std;
int T,n,m,k,h,a[maxn],v[5][maxl],cnt,wrk[maxl];
bool id[maxl],vis[maxl];
multiset<int>s;
inline int read(){
	int ret=0;char f=1,ch=getchar();
	while(!isdigit(ch)) f=(ch=='-'?-f:f),ch=getchar();
	while(isdigit(ch)) ret=ret*10+ch-'0',ch=getchar();
	return ret;
}
struct str{
	int id,s,x,y;
}q[maxn<<1];
void work2(){
	while(T--){
		n=read(),m=read(),k=read(),h=0;s.clear();
		memset(v,0,sizeof v);memset(wrk,0,sizeof wrk);
		for(int i=1;i<n;++i) s.insert(i),s.insert(i);
		for(int i=1;i<=m;++i) a[i]=read();
		for(int i=1;i<=m;++i){
			if(!wrk[a[i]]){
				if(s.empty()){int l=0;memset(vis,0,sizeof vis);
					for(int j=i+1;a[j]!=a[i];++j)
						if(v[0][wrk[a[j]]]==a[j]&&!vis[v[1][wrk[a[j]]]]){l=wrk[a[j]];break;}
						else vis[a[j]]=1;
					if(l==0) q[i]=(str){1,n},wrk[a[i]]=n;
					else q[i]=(str){1,l},wrk[a[i]]=l,v[2][l]=a[i],++h;
				}else{
					wrk[a[i]]=*s.begin();s.erase(s.begin());
					if(v[0][wrk[a[i]]]) v[1][wrk[a[i]]]=a[i];
					else v[0][wrk[a[i]]]=a[i];q[i]=(str){1,wrk[a[i]]};++h;
				}
			}else{
				if(wrk[a[i]]==n){q[i]=(str){1,n};wrk[a[i]]=0,v[0][wrk[a[i]]]=0;continue;}
				if(v[2][wrk[a[i]]]==a[i]){
					q[i]=(str){1,wrk[a[i]]};v[2][wrk[a[i]]]=0;h++;
				}else if(v[1][wrk[a[i]]]==a[i]){
					q[i]=(str){1,wrk[a[i]]};v[1][wrk[a[i]]]=0;h++;
				}else if(v[0][wrk[a[i]]]==a[i]){
					if(!v[1][wrk[a[i]]]){q[i]=(str){1,wrk[a[i]]};v[0][wrk[a[i]]]=0;h++;}
					else{
						q[i]=(str){2,n,n,wrk[a[i]]};v[0][wrk[a[i]]]=v[1][wrk[a[i]]],v[1][wrk[a[i]]]=v[2][wrk[a[i]]],v[2][wrk[a[i]]]=0;h+=2;
					}
				}s.insert(wrk[a[i]]);wrk[a[i]]=0;
			}
		}printf("%d\n",h);
		for(int i=1;i<=m;i++) if(q[i].id==1) printf("1 %d\n",q[i].s);else printf("1 %d\n2 %d %d\n",q[i].s,q[i].x,q[i].y);
	}
}
void work1(){
	while(T--){
		n=read(),m=read(),k=read(),h=0;
		memset(v,0,sizeof v);memset(id,0,sizeof id);
		for(int i=1;i<=m;++i) a[i]=read();
		for(int i=1;i<=m;++i){
			int x=a[i]%n+a[i]/n;
			if(id[a[i]]==0){
				q[i]=(str){1,x},h++;
				if(!v[0][x]) v[0][x]=a[i];
				else v[1][x]=a[i];id[a[i]]=1;
			}else{
				if(v[0][x]==a[i]){
					if(v[1][x]!=0)q[i]=(str){2,n,n,x},id[a[i]]=0,v[0][x]=v[1][x],v[1][x]=0,h+=2;
					else q[i]=(str){1,x},id[a[i]]=0,v[0][x]=0,h++;
				}else q[i]=(str){1,x},v[1][x]=0,id[a[i]]=0,h++;
			}
		}
		printf("%d\n",h);
		for(int i=1;i<=m;i++) if(q[i].id==1) printf("1 %d\n",q[i].s);else printf("1 %d\n2 %d %d\n",q[i].s,q[i].x,q[i].y);
	}
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	if(T%10==1) work1();
	else work2();
	return 0;
}