#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define par pair<int,int>
#define pb push_back
#define mkp make_pair
using namespace std;
const int M=2e6+5,N=305,mod=998244353;
ll RD(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
	return x*f;
}
int n,m,k;
int a[M];
struct Out{int op,s1,s2;}o[M];int cnt;
int st[2][N];
int ex[N];
int bl[N];
void Op(int s1,int s2){
	cnt++;
	if(s2!=0)o[cnt].op=2,o[cnt].s1=s1,o[cnt].s2=s2;
	else o[cnt].op=1,o[cnt].s1=s1,o[cnt].s2=s2;
}
void sub1(){
	ex[0]=0;
	for(int i=1;i<=k;i++)bl[i]=0;
	for(int i=1;i<=n;i++)ex[++ex[0]]=i,st[0][i]=st[1][i]=0;
	for(int i=1;i<=m;i++)
	{
		if(bl[a[i]]==0)
		{
			int x=ex[ex[0]];
			bl[a[i]]=x;Op(x,0);
			if(st[0][x]==0)
			{
				st[0][x]=a[i];
			}
			else
			{
				ex[0]--;
				st[1][x]=a[i];
			}
		}
		else
		{
			if(st[0][bl[a[i]]]==a[i])
			{
				Op(ex[0],0);
				Op(ex[0],bl[a[i]]);
				st[0][bl[a[i]]]=st[1][bl[a[i]]];
				st[1][bl[a[i]]]=0;
				if(st[0][bl[a[i]]]==0)ex[++ex[0]]=st[0][bl[a[i]]];
			}
			else
			{
				Op(bl[a[i]],0);
				st[1][bl[a[i]]]=0;
			}
			bl[a[i]]=0;
		}
	}
}
int s1[M],s2[M];int t1,t2;
void sub2(){
	t1=t2=0;
	int l=1,r=0;
	bool f[4]={0,0,0,0};
	while(r<=m)
	{
		int x=0;
		while(r<=m)
		{
			r++;
			if(f[a[r]])
			{
				x=a[r];break;
			}
			else
			{
				f[a[r]]=1;
			}
		}
		
	}
}
void solve(){
	cnt=0;
	
	n=RD(),m=RD(),k=RD();
	for(int i=1;i<=m;i++)a[i]=RD();
	sub1();
	
	printf("%d\n",cnt);
	for(int i=1;i<=cnt;i++)
	{
		printf("%d ",o[i].op);
		if(o[i].op==1)printf("%d\n",o[i].s1);
		else printf("%d %d\n",o[i].s1,o[i].s2);
	}
}

int main(){
	
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	
	
	int T=RD();
	while(T--)solve();
	return 0;
}
/*
1
6 20 10
1 2 3 4 5 6 7 8 9 10 1 4 2 3 10 6 9 7 5 8

*/