#include<bits/stdc++.h>
#define Pc(x) putchar(x)
#define PB push_back
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
using namespace std;using ll=long long;using ull=unsigned ll;
const int N=1e3+5,M=2e6+5,eps=1e-5,INF=1e9+7,mod=998244353;
int n,m,k,T[N][2],Si[N],Pl[N],f[N],La[M],A[M],Op[2*M],X[2*M],Y[2*M],H,Fl[N];deque<int> Q[N];
void M1(int x){Op[++H]=1;X[H]=x;}
void M2(int x,int y){Op[++H]=2;X[H]=x;Y[H]=y;}
void Ins(int x){
	int i,EPT=0;for(i=1;i<=n;i++) if(Q[i].empty()) {EPT=i;break;}
	for(i=1;i<=n;i++) if(!Q[i].empty()&&La[x]<La[Q[i].back()]) return M1(i),Q[i].push_back(x);
	for(i=1;i<=n;i++){
		if(!Q[i].empty()&&La[x]>La[Q[i].back()]){
			if(Q[i].size()==1) return M1(i),Q[i].push_back(x);
			else {
				int p=Q[i].back();Q[i].pop_back();int p2=Q[i].back();Q[i].push_back(p);
				if(La[p2]<La[p]) return M1(i),Q[i].push_back(x);
			}
		} 
	} 
	if(EPT){
		return M1(EPT),Q[EPT].push_back(x);
	}
	int Mx=0,Ans=0;for(i=1;i<=n;i++) if(Q[i].size()==1) Ans<La[Q[i].back()]&&(Ans=La[Q[i].back()],Mx=i);
	M1(Mx);Q[Mx].PB(x);
}
void Solve(){
	int i,j;scanf("%d%d%d",&n,&m,&k);for(i=1;i<=m;i++) scanf("%d",&A[i]);
	H=0;Me(Pl,0);if(k==2*n-2){
		for(i=1;i<=m;i++){
			int p=(A[i]<=n-1?A[i]:A[i]-n+1);
			if(Fl[A[i]]) {
				if(Q[p].front()==A[i]) M1(n),M2(p,n),Q[p].pop_front();
				else M1(p),Q[p].pop_back();
			}else M1(p),Q[p].push_back(A[i]);
			Fl[A[i]]^=1;
		}
	}else{
		for(i=1;i<=k;i++) f[i]=m+1;for(i=m;i;i--) {
			La[A[i]]=f[A[i]];f[A[i]]=i;
		}
		for(i=1;i<=m;i++){
			if(Fl[A[i]]){
				int EPT=0;for(j=1;j<=n;j++) if(Q[j].empty()) {EPT=j;break;}
				for(j=1;j<=n;j++)if(!Q[j].empty()){
					if(A[Q[j].back()]==A[i]) {M1(j);Q[j].pop_back();break;}
					else if(A[Q[j].front()]==A[i]){M1(EPT);M2(j,EPT);Q[j].pop_front();break;}
				}
			}else{
				Ins(i);
			}
			Fl[A[i]]^=1;
		}
	}	
	printf("%d\n",H);
	for(i=1;i<=H;i++) Op[i]==1?(printf("%d %d\n",1,X[i])):(printf("2 %d %d\n",X[i],Y[i]));
}
int main(){
	freopen("meow.in","r",stdin);freopen("meow.out","w",stdout);
	int T;scanf("%d",&T);while(T--) Solve();
}