//dev=m28=xie
#include<bits/stdc++.h>
using namespace std;
int now[400],now2[400],wmh[1000],a[2100000];
int r[400],cnt,w,v[400];
vector<pair<int,int> > ans;
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int _;
	cin>>_;
	while(_--){
		ans.clear();
		int n,m,kkk;
		scanf("%d%d%d",&n,&m,&kkk);
		for(int i=1;i<=n;i++)now[i]=now2[i]=0;
		for(int i=1;i<=2*n-1;i++)wmh[i]=0;
		for(int i=1;i<=n-1;i++)r[i]=i;
		cnt=n-1;
		w=n;
		for(int i=1;i<=m;i++)scanf("%d",&a[i]);
		for(int i=1;i<=m;){
			int jjj=a[i];
			if(wmh[jjj]){
				int y=wmh[jjj];
				if(now2[y]==jjj||now2[y]==0){
					ans.push_back(make_pair(-1,y));
					if(now2[y]==0)now[y]=0;
					else now2[y]=0,r[++cnt]=y;
					wmh[jjj]=0;
				}
				else{
					r[++cnt]=y;
					now[y]=now2[y];
					now2[y]=0;
					wmh[jjj]=0;
					ans.push_back(make_pair(-1,w));
					ans.push_back(make_pair(y,w));
				}
				i++;
				continue;
			}
			if(cnt){
				wmh[jjj]=r[cnt];
				ans.push_back(make_pair(-1,wmh[jjj]));
				if(now[wmh[jjj]]){
					now2[wmh[jjj]]=jjj;
					cnt--;
				}
				else{
					now[wmh[jjj]]=jjj;
				}
				i++;
				continue;
			}
			for(int ii=i+1;;ii++){
				if(a[ii]==a[i]){
					ans.push_back(make_pair(-1,w));
					for(int j=i+1;j<ii;j++)ans.push_back(make_pair(-1,wmh[a[j]]));
					ans.push_back(make_pair(-1,w));
					for(int j=i+1;j<ii;j++)v[wmh[a[j]]]^=1;
					for(int j=i+1;j<ii;j++)if(v[wmh[a[j]]]){
						now2[wmh[a[j]]]=0,r[++cnt]=wmh[a[j]];
						v[wmh[a[j]]]=0;
						wmh[a[j]]=0;
					}
					i=ii+1;
					break;
				}
				if(now[wmh[a[ii]]]==a[ii]){
				int tt=now2[wmh[a[ii]]];
				int oo=0;
				for(int j=i+1;j<ii;j++)if(a[j]==tt)oo^=1;
				if(oo){
					ans.push_back(make_pair(-1,w));
					now[w]=a[i];
					wmh[a[i]]=w;
					r[++cnt]=w;
					for(int j=i+1;j<=ii;j++)ans.push_back(make_pair(-1,wmh[a[j]]));
					for(int j=i+1;j<ii;j++)v[wmh[a[j]]]^=1;
					for(int j=i+1;j<ii;j++)if(v[wmh[a[j]]]){
						if(a[j]!=tt)now2[wmh[a[j]]]=0,r[++cnt]=wmh[a[j]];
						v[wmh[a[j]]]=0;
						wmh[a[j]]=0;
					}
					w=wmh[a[ii]];
					now[w]=now2[w]=0;
					wmh[a[ii]]=0;
				}
				else{
					ans.push_back(make_pair(-1,wmh[a[ii]]));
					for(int j=i+1;j<ii;j++)ans.push_back(make_pair(-1,a[j]==tt ? w : wmh[a[j]]));
					for(int j=i+1;j<ii;j++)if(a[j]!=tt)v[wmh[a[j]]]^=1;
					for(int j=i+1;j<ii;j++)if(v[wmh[a[j]]]){
						now2[wmh[a[j]]]=0,r[++cnt]=wmh[a[j]];
						v[wmh[a[j]]]=0;
						wmh[a[j]]=0;
					}
					ans.push_back(make_pair(-1,w));
					ans.push_back(make_pair(w,wmh[a[ii]]));
					int yz=wmh[a[ii]];
					wmh[a[ii]]=0;
					now[yz]=now2[yz];
					now2[yz]=a[i];
					wmh[a[i]]=yz;
				}
				i=ii+1;
				break;
			    }
		    }
		}
		printf("%d\n",ans.size());
		for(pair<int,int> k : ans){
			if(k.first==-1)printf("1 %d\n",k.second);
			else printf("2 %d %d\n",k.first,k.second);
		}
	}
	return 0;
}