#include<bits/stdc++.h>
#define gc getchar()
using namespace std;
template <class T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=gc;
	while (!isdigit(ch))
	{
		if (ch=='-') f=-1;
		ch=gc;
	}
	while (isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=gc;
	}
	x*=f;
	return;
}
struct carddd
{
	int col,num,gt,pe;
}cd[2002000];

int colp[1000];
struct zh
{
	int nu[2000],bm,tp;
}zn[1000];
int ans[2002000][3],op;
unsigned long long T,n,m,k,x,cnt,znum;
inline void wx()
{
	for (int i=1;i<=m;i++)
	{
		for (int j=1;j<=n;j++)
		{
			if (j==cd[cd[i].pe].gt)
			{
				if (zn[j].nu[zn[j].tp]==cd[i].pe)
				{
					op++;
					ans[op][0]=1;
					ans[op][1]=j;
					zn[j].tp--;
					break;
				}
				else continue;
			}
			if (zn[j].bm==zn[j].tp+1)
			{
				zn[j].tp++;
				zn[j].nu[zn[j].tp]=i;
				op++;
				ans[op][0]=1;
				ans[op][1]=j;
				for (int ii=1;ii<=m;ii++)
				{
					if ((cd[zn[ii].nu[zn[ii].bm]].col==cd[i].col)&&(ii!=j))
					{
						zn[ii].bm++;
						zn[j].tp--;
						op++;
						ans[op][0]=2;
						ans[op][1]=min(ii,j);
						ans[op][2]=max(ii,j);
					}
				}
				
				break;
			}
			else if (cd[zn[j].nu[zn[j].tp]].pe<=cd[i].pe)
			{
				zn[j].tp++;
				zn[j].nu[zn[j].tp]=i;
				op++;
				ans[op][0]=1;
				ans[op][1]=j;
				break;
			}
		}
	}
	
}
signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	
	bool fl=false;
	read(T);
	while (T--)
	{
		cnt=0;
		op=0;
		read(n),read(m),read(k);
		for (int i=1;i<=n;i++)
		{
			zn[i].bm=1;
			zn[i].tp=0;
		}
		for (int i=1;i<=k;i++)
		{
			colp[i]=0;
		}
		//init over
		for (int i=1;i<=m;i++)
		{
			read(cd[i].col);
			if (colp[cd[i].col])//front yi3 you3
			{
				cd[i].pe=colp[cd[i].col];
				cd[cd[i].pe].pe=i;
				colp[cd[i].col]=0;
			}
			else//front mei2 you3
			{
				colp[cd[i].col]=i;
			}
		}
		//pei4 dui4 over
		wx();
		cout<<op<<'\n';
		for (int i=1;i<=op;i++)
		{
			cout<<ans[i][0]<<' ';
			if (ans[i][0]==1)
			{
				cout<<ans[i][1]<<'\n';
			}
			else
			{
				cout<<ans[i][1]<<' '<<ans[i][2]<<'\n';	
			}
		}
	}
	return 0;
}
