#include<bits/stdc++.h>//Good luck!
#define gc getchar
#define pc putchar
#define F(i,x,y) for(int i=x;i<=y;++i)
#define R(i,x,y) for(int i=x;i>=y;--i)
#define min std::min
#define max std::max
typedef long long LL;
inline int read(){
	int x=0;char ch=gc();bool p=1;
	while (!isdigit(ch)) ch=='-'?p=0:0,ch=gc();
	while ( isdigit(ch)) x=(x<<1)+(x<<3)+(ch^'0'),ch=gc();
	return p?x:-x;
}
const int N=305,M=2e6+5;
int p[N][5],idx[N],A[M],st[N],top,pre[N*2],n,m,k,nxt[M],ne[N*2],maxk;
int op,B[M*2],C[M*2];
inline void Work1(){
	top=0;
	op=0;
	F(i,1,n-1) st[++top]=i;
	F(i,1,m){
		if (!pre[A[i]]){
			int now=st[top];
			p[now][idx[now]++]=A[i];
			pre[A[i]]=now;
			B[++op]=now;
			if (idx[now]==2) --top;
		}else{
			int now=pre[A[i]];
			//printf("now = %d\n",now);
			if (A[i]==p[now][0]){
				//printf("i = %d\n",i);
				B[++op]=n;
				B[++op]=now;
				C[op]=n;
				p[now][0]=p[now][1];
				--idx[now];
				if (idx[now]==1) st[++top]=now;
			}else{
				B[++op]=now;
				--idx[now];
				if (idx[now]==1) st[++top]=now;
			}
			pre[A[i]]=0;
		}
	}
	printf("%d\n",op);
	F(i,1,op){
		if (C[i]){
			printf("2 %d %d\n",B[i],C[i]);
		}else{
			printf("1 %d\n",B[i]);
		}
	}
}
inline void Work2(){
	top=0;
	op=0;
	F(i,1,n-1) st[++top]=i;
	R(i,m,1){
		if (ne[A[i]]){
			nxt[i]=ne[A[i]];
		}
		ne[A[i]]=i;
	}
	F(i,1,m){
		if (!pre[A[i]]){
			if (st[top]){
				int now=st[top];
				p[now][idx[now]++]=i;
				pre[A[i]]=now;
				B[++op]=now;
				if (idx[now]==2){
					--top;
					if (nxt[p[now][1]]>=nxt[p[maxk][1]]) maxk=now;
				}
			}else{
				p[maxk][++idx[maxk]]=i;
				B[++op]=maxk;
				maxk=0;
			}
		}else{
			int now=pre[A[i]];
			//printf("now = %d\n",now);
			if (A[i]==A[p[now][0]]){
				//printf("i = %d\n",i);
				B[++op]=n;
				B[++op]=now;
				C[op]=n;
				p[now][0]=p[now][1];
				--idx[now];
				if (idx[now]==1) st[++top]=now;
			}else{
				B[++op]=now;
				--idx[now];
				if (idx[now]==1) st[++top]=now;
			}
			pre[A[i]]=0;
		}
	}
	printf("%d\n",op);
	F(i,1,op){
		if (C[i]){
			printf("2 %d %d\n",B[i],C[i]);
		}else{
			printf("1 %d\n",B[i]);
		}
	}
}
signed main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int t=read();
	while (t--){
		n=read(),m=read(),k=read();
		F(i,1,m) A[i]=read();
		if (k==2*n-2) Work1();
		else Work2();
	}
	return 0;
}
