#include<bits/stdc++.h>
//#define int long long
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);++(i))
#define per(i,a,b) for(int (i)=(a);(i)>=(b);--(i))
using namespace std;
inline int read()
{
	int f=1,x=0; char c=getchar();
	while(!isdigit(c)) f=c=='-'?-1:1,c=getchar();
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c-'0'),c=getchar();
	return f*x;
}
inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
	return void();
}
const int N=4e6+520,M=3e4;
int T,n,m,a[N],b[N],tot,k,vis[N];
int cnt,ans1[N],ans2[N];
int pos[N];
int q[320][M],l[320],r[320];
bool now[320];
signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	while(T--)
	{
		n=read(),m=read(),k=read();
		rep(i,1,m) a[i]=read();
		rep(i,1,m)
		{
			if(vis[a[i]]) 
			{
				++tot;
				b[vis[a[i]]]=b[i]=tot;
			    vis[a[i]]=0;
			}
			else vis[a[i]]=i;
		}
		rep(i,1,n) l[i]=1,r[i]=0,now[i]=0;
		rep(i,1,m)
		{
			if(!vis[a[i]])
			{
				vis[a[i]]=i;
			    rep(j,1,n)
			    {
				    if(!now[j]&&b[i]>b[q[j][r[j]]])
				    {
				        q[j][++r[j]]=i;
				        pos[i]=j;
				        ++cnt;
				        ans1[cnt]=j;
				        break;
				    }
				    else if(!now[j]) 
				    {
					    q[j][++r[j]]=i,now[j]=1;
					    pos[i]=j;
					    ++cnt;
					    ans1[cnt]=j;
					    break;
				    }
				}
			}
			else
			{
				int x=vis[a[i]];
				if(q[pos[x]][r[pos[x]]]==x)
				{
					++cnt;
					ans1[cnt]=pos[x];
					if(now[pos[x]]) now[pos[x]]=0;
					--r[pos[x]];
				}
				else
				{
					int o=0;
					rep(j,1,n) if(l[j]>r[j]) o=j;
					++cnt;
					ans1[cnt]=o;
					++cnt;
					ans1[cnt]=o,ans2[cnt]=pos[x];
					++l[pos[x]];
					if(r[pos[x]]-l[pos[x]]<=0) now[pos[x]]=0;
				}
				vis[a[i]]=0;
			}
		}
//		rep(i,1,n) if(r[i]>=l[i]) puts("NO");
		write(cnt),putchar('\n');
		rep(i,1,cnt)
		{
			if(ans2[i])
			{
				putchar('2'),putchar(' ');
				write(ans1[i]),putchar(' '),write(ans2[i]);
			}
			else
			{
				putchar('1'),putchar(' ');
				write(ans1[i]);
			}
			ans2[i]=ans1[i]=0;
			putchar('\n');
		}
		cnt=0;
		//break;
	}
	return 0;
}
