#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define CI const int
#define int long long
using namespace std;
const int N=605,M=2e6+5;
int T,n,m,k,cnt,a[M],rec[N][5];
int read(int& v)
{
	char ch; int f=1;
	for(ch='*';!isdigit(ch) && ch!='-';ch=getchar());
	if(ch=='-')  f=-1,ch=getchar();
	for(v=0;isdigit(ch);v=v*10+ch-'0',ch=getchar());
	v*=f;
return v;
}
struct node
{
	int id,dep;
	node(CI& a,CI& b):id(a),dep(b){}
	node(){}
}p[N];
struct Ans
{
	int op,x,y;
	Ans(CI& a,CI& b,CI& c):op(a),x(b),y(c){}
	Ans(){}
}ans[N];
namespace sub1
{
	int rec[N];
	void main()
	{
		queue<int> q0,q1;
		for(int i=1;i<n;i++)  q0.push(i);
		for(int i=1;i<=k;i++)  p[i]=node(0,0);
		for(int i=1;i<=m;i++)
		{
			int x=a[i];
			if(!p[x].id)
			{
				int id;
				if(!q0.empty())
				{
					id=q0.front(),q0.pop();
					q1.push(id);
					p[x]=node(id,1);
					ans[++cnt]=Ans(1,id,0);
					rec[id]=1;
					continue;
				}
				if(!q1.empty())
				{
					id=q1.front(),q1.pop();
					p[x]=node(id,2);
					ans[++cnt]=Ans(1,id,0);
					rec[id]=2;
					continue;
				}
			}
			else
			{
				int id=p[x].id,dep=p[x].dep;
				if(dep==1)
				{
					ans[++cnt]=Ans(1,n,0);
					ans[++cnt]=Ans(2,id,n);
					rec[id]--;
					if(rec[id]==0)  q0.push(id);
					if(rec[id]==1)  q1.push(id);
				}
				if(dep==2)
				{
					ans[++cnt]=Ans(1,id,0);
					rec[id]--;
					if(rec[id]==0)  q0.push(id);
					if(rec[id]==1)  q1.push(id);
				}
			}
		}
		printf("%lld\n",cnt);
		for(int i=1;i<=cnt;i++)
			if(ans[i].op==1)  printf("1 %lld\n",ans[i].x);
			else  printf("2 %lld %lld\n",ans[i].x,ans[i].y);
	}
}
namespace sub2
{
	int cnt=0,flag=0,s[N];
	int q[5][N];
	bool check()
	{
		int l1=1,r1=0;
		int l2=1,r2=0;
		int l3=1,r3=0;
		for(int i=1;i<=m;i++)
		{
			if(s[i]==1)  q[1][++r1]=a[i];
			if(s[i]==2)  q[2][++r2]=a[i];
			if(s[i]==3)  q[3][++r3]=a[i];
			ans[++cnt]=Ans(1,s[i],0);
			while(l1<=r1-1 && q[1][r1]==q[1][r1-1])  r1-=2;
			while(l2<=r2-1 && q[2][r2]==q[2][r2-1])  r2-=2;
			while(l3<=r3-1 && q[3][r3]==q[3][r3-1])  r3-=2;
			while(l1<=r1 && l2<=r2 && q[1][l1]==q[2][l2])
				ans[++cnt]=Ans(2,1,2),l1++,l2++;
			while(l1<=r1 && l3<=r3 && q[1][l1]==q[3][l3])
				ans[++cnt]=Ans(2,1,3),l1++,l3++;
			while(l2<=r2 && l3<=r3 && q[2][l2]==q[3][l3])
				ans[++cnt]=Ans(2,2,3),l2++,l3++;
		}
		return (l1>r1)&&(l2>r2)&&(l3>r3);
	}
	void dfs(int p)
	{
		if(p>m)
		{
			cnt=0;
			if(check())  flag=1;
			return;
		}
		if(!flag)  s[p]=1,dfs(p+1);
		if(!flag)  s[p]=2,dfs(p+1);
		if(!flag)  s[p]=3,dfs(p+1);
	}
	void main()
	{
		flag=cnt=0;
		dfs(1);
		printf("%lld\n",cnt);
		for(int i=1;i<=cnt;i++)
			if(ans[i].op==1)  printf("1 %lld\n",ans[i].x);
			else  printf("2 %lld %lld\n",ans[i].x,ans[i].y);
	}
}
void solve()
{
	cnt=0;
	read(n),read(m),read(k);
	for(int i=1;i<=m;i++)  read(a[i]);
	if(k==2*n-2){ sub1::main(); return; }
	if(n==3){ sub2::main(); return; }
	printf("%lld\n",m);
	for(int i=1;i<=m;i++)  printf("1 1\n");
}
signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	read(T);
	while(T--)  solve();
return 0;
}