//I love Noelle forever!
#include<bits/stdc++.h>
using namespace std;
int t,n,m,k;
int a[2000010];
int p[2000010],nxt[2000010],lst[100010];
vector<int> v[100010];
int read()
{
	char c=getchar();
	while(c<'0'||c>'9')
		c=getchar();
	int res=0;
	while(c>='0'&&c<='9')
		res=res*10+c-'0',c=getchar();
	return res;
}
int uzi=0;
struct node
{
	int x,y,z;
};
vector<node> ans;
int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	t=read();
	while(t--)
	{
		n=read();m=read();k=read();
		for(int i=1;i<=m;i++)
			a[i]=read();
		for(int i=1;i<=n;i++)
			v[i].clear();
		for(int i=1;i<=k;i++)
			lst[i]=n+1;
		for(int i=m;i>=1;i--)
		{
			nxt[i]=lst[a[i]];
			lst[a[i]]=i;
		}
		for(int i=1;i<=m;i++)
		{
			int emp=0,ok=0;
			for(int j=1;j<=n;j++)
			{
				if(v[j].size()&&a[v[j].back()]==a[i])
				{
					ok=1;
					ans.push_back((node){1,j});
					v[j].pop_back();
					break;
				}
			}
			if(ok)
				continue;
			int tot=0;
			for(int j=1;j<=n;j++)
				if(v[j].size()==0)
					emp=j,tot++;
			if(emp)
			{
				for(int j=1;j<=n;j++)
					if(v[j].size()&&a[v[j].front()]==a[i])
					{
						ok=1;
						v[j].erase(v[j].begin());
						ans.push_back((node){1,emp,0});
						ans.push_back((node){2,j,emp});
						break;
					}
			}
			if(ok)
				continue;
			for(int j=1;j<=n;j++)
				if(v[j].size()==1&&nxt[i]>nxt[v[j].back()])
				{
					ans.push_back((node){1,j});
					v[j].push_back(i);	
					ok=1;
					break;
				}
			if(ok)
				continue;
			if(tot>=2)
			{
				ans.push_back((node){1,emp});
				v[emp].push_back(i);
				continue;
			}
			for(int j=1;j<=n;j++)
			{
				if(v[j].size()==2&&(nxt[v[j].front()]<nxt[v[j].back()]||nxt[i]<nxt[v[j].back()]))
				{
					v[j].push_back(i);
					ans.push_back((node){1,j});
					ok=1;
					break;
				}
			}
			if(ok)
				continue;
			for(int j=1;j<=n;j++)
				if(v[j].size()==1&&nxt[i]<nxt[v[j].back()])
				{
					ans.push_back((node){1,j});
					v[j].push_back(i);	
					ok=1;
					break;
				}
			if(ok)
				continue;
		}
		printf("%d\n",(int)ans.size());
		for(node x:ans)
			if(x.x==2)
				printf("%d %d %d\n",x.x,x.y,x.z);
			else
				printf("%d %d\n",x.x,x.y);
		ans.clear();
	}
}

