#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
struct Mode
{
	 int cz,id;
}jl[4000010];
long long t1;
long long t[610],mp[610],bj[2000010],bj1[2000010],a1[2000010],jl1;
bool f;
long long n,m,k,czs,a,xb,z[610][5],ss;
long long read()
{
	 long long f=1,ans=0;
	 char c;
	 c=getchar();
	 while (((c>'9')||(c<'0'))&&(c!='-'))
	  c=getchar();
	 if (c=='-')
	  {
	  	 f=-1;
	  	 c=getchar();
	  }
	 while ((c<='9')&&(c>='0'))
	   ans=(ans<<1)+(ans<<3)+(c-'0'),c=getchar();
	   return ans*f;
}
 int main()
 {
 	 freopen("meow.in","r",stdin);
 	 freopen("meow.out","w",stdout);
 	 t1=read();
 	 while (t1--)
 	 {
 	    n=read();
 	    m=read();
 	    k=read();
 	    memset(t,0,sizeof(t));
 	    memset(z,0,sizeof(z));
 	    memset(mp,0,sizeof(mp));
 	    memset(bj,0,sizeof(bj));
 	    memset(bj1,0,sizeof(bj1));
 	    czs=0;
 	if (k==2*n-2)
 	{
		for (int i=1;i<=m;i++)
		{
		   a=read();
		    xb=(a-1)/2+1;
			if ((z[xb][1]==a)&&(t[xb]==1))
			 	jl[++czs].cz=1,jl[czs].id=xb,t[xb]=0;
			else
			if ((z[xb][1]==a)&&(t[xb]==2))
			    jl[++czs].cz=1,jl[czs].id=n,jl[++czs].cz=2,jl[czs].id=xb,z[xb][1]=z[xb][2],t[xb]=1;
			else
			if ((z[xb][2]==a)&&(t[xb]==2))
			jl[++czs].cz=1,jl[czs].id=xb,t[xb]=1;
			else
			jl[++czs].cz=1,jl[czs].id=xb,z[xb][++t[xb]]=a;
		}
		printf("%lld\n",czs);
		for (int i=1;i<=czs;i++)
		 if (jl[i].cz==1)
		  printf("1 %lld\n",jl[i].id);
		 else
		 printf("2 %lld %lld\n",jl[i].id,n);
	}
	else
	 {
	 	czs=0;
	 	ss=0;
	 	 for (int i=1;i<=m;i++)
	 	     	a1[i]=read();
	 	  for (int i=1;i<=m;i++)
	 	  {
	 	    if (mp[a1[i]])
	 	      mp[a1[i]]=0,ss--;
			  else
			  mp[a1[i]]=1,ss++;
			if (ss==k)
			bj[i+1]=1;
		  }
		jl1=0;
		  for (int i=m;i>=1;i--)
		   if (bj[i]==1)
		      jl1=a1[i];
		   else
		   if (jl1==a1[i])
		      jl1=0,bj1[i]=1;
	      for (int i=1;i<=m;i++)
	        if (bj1[i])
	        {
	            for (int j=1;j<n;j++)
				  if (t[j]==0)
				  {
				  	 z[j][1]=a1[i];
				  	 jl[++czs].cz=1,jl[czs].id=j,t[j]=1;
				  	 break;
		          }
		    }
		     else
		     if (bj[i+1])
		     {
		     	for (int j=1;j<n;j++)
		     	 if ((z[j][1]==a1[i+1])&&(t[j]))
		     	 {
		     	 	 z[j][++t[j]]=a1[i];
		     	 	 jl[++czs].cz=1,jl[czs].id=j;
		     	     break;	
				 }
			  }
			 else
			 {
			 	 f=0;
			 	 for (int j=1;j<n;j++)
                   if ((z[j][1]==a1[i])&&(t[j]))
                    {
                       f=1;
					   jl[++czs].cz=1;
					   jl[czs].id=n;
					   jl[++czs].cz=2;
					   jl[czs].id=j;
					   for (int k=1;k<t[j];k++)
					    z[j][k]=z[j][k+1];
					    t[j]--;
					   break; 	
					}
				   else
				   if (z[j][t[j]]==a1[i])
				   {
				   	  f=1;
				   	  jl[++czs].cz=1;
					  jl[czs].id=j;
					  t[j]--;
					  break;
				   }
				 if (!f)
				  for (int j=1;j<n;j++)
				   if (t[j]==1)
				   {
				   	 f=1;
				   	 jl[++czs].cz=1;
				   	 jl[czs].id=j;
				   	 z[j][++t[j]]=a1[i];
				   	 break;
				   }
				 if (!f)
				  for (int j=1;j<n;j++)
				   if (t[j]==0)
				   {
				   	 f=1;
				   	 jl[++czs].cz=1;
				   	 jl[czs].id=j;
				   	 z[j][++t[j]]=a1[i];
				   	 break;
				   }
			 }
		printf("%lld\n",czs);
		for (int i=1;i<=czs;i++)
		 if (jl[i].cz==1)
		  printf("1 %lld\n",jl[i].id);
		 else
		 printf("2 %lld %lld\n",jl[i].id,n);
	 }
    }
 	 fclose(stdin);
 	 fclose(stdout);
 	 return 0;
 }