#include <bits/stdc++.h>
using namespace std;

int t,n,m,k,step,a,z[301][1000],l[1000],r[1000],rm = 1,p[10000][3],pre;

void pd(int ll);
int main()
{
	freopen ("meow.in","r",stdin);
	freopen ("meow.out","w",stdout);
	scanf ("%d",&t);
	for (int turns = 0;turns < t;turns++)
		{
			scanf ("%d%d%d",&n,&m,&k);
			for (int i = 1;i <= m;i++)
				{
					scanf ("%d",&a);
					pd(a);
				}
			step += m;
			printf ("%d\n",step);
			for (int i = 1;i <= pre;i++)
				if (p[i][0] == 0)
					printf ("0 %d",p[i][1]);
					else
						printf ("1 %d %d",p[i][1],p[i][2]);
		}
	return 0;
}
void pd(int ll)
{
	bool op = true;
	for (int i = 1;i <= n;i++)
		if (ll == z[i][r[i]])
			{
				z[i][r[i]] = 0;
				r[i]--;
				op = false;
				p[++pre][1] = i;
				p[pre][0] = 0;
				break;
			}
	if (rm != m)
		for (int i = 1;i <= n;i++)
			if (ll == z[i][l[i]])
				{
					z[i][l[i]] = 0;
					l[i]++;
					step++;
					p[++pre][1] = i;
					p[pre][0] = 1;
					p[pre][2] = rm + 1;
					return;
				}
	if (op)
		{
			if (sizeof(z[rm]) > m / n)
				{
					z[++rm][0] = ll,r[rm]++;
					p[++pre][1] = rm;
					p[pre][0] = 0;
				}
				else
					{
						z[rm][++l[rm]] = ll,r[rm]++;
					}
		}
}