// Author:A weak man named EricQian
// Attention:Check your code while coding
// 15 pts
#include<bits/stdc++.h>
using namespace std;
#define infll 0x3f3f3f3f3f3f3f3fll
#define inf 0x3f3f3f3f
#define pb push_back
#define eb emplace_back
#define pa pair<int,int>
#define fi first
#define se second
#define all(x) ((x).bgein(),(x).end())
typedef long long ll;
#define Maxn 305
#define Maxm 2000005
inline int rd()
{
	int x=0;
	char ch,t=0;
	while(!isdigit(ch = getchar())) t|=ch=='-';
	while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
	return t?-x:x;
}
int T,n,m,k,op;
int a[Maxm],typ[Maxm],s1[Maxm],s2[Maxm];
inline void addop(int _typ,int _s1,int _s2=0)
{
	op++;
	if(_typ==1) typ[op]=1,s1[op]=_s1;
	else typ[op]=2,s1[op]=_s1,s2[op]=_s2;
}
namespace subtask1
{
	int Up[Maxn],Down[Maxn];
	void solve()
	{
		memset(Up,-1,sizeof(Up));
		memset(Down,-1,sizeof(Down));
		for(int i=1,bel;i<=m;i++)
		{
			bel=(a[i]-1)%(n-1)+1;
			if(Up[bel]==-1) Up[bel]=a[i],addop(1,bel);
			else
			{
				if(Up[bel]==a[i])
					Up[bel]=Down[bel],Down[bel]=-1,addop(1,n),addop(2,bel,n);
				else if(Down[bel]!=-1) Down[bel]=-1,addop(1,bel);
				else Down[bel]=a[i],addop(1,bel);
			}
		}
		printf("%d\n",op);
		for(int i=1;i<=op;i++)
		{
			if(typ[i]==1) printf("1 %d\n",s1[i]);
			else printf("2 %d %d\n",s1[i],s2[i]);
		}
	}
}
namespace subtask2
{
	int hav[5];
	void solve()
	{
		addop(1,1);
		for(int cur=a[1],unused=2,nex,r,cursta=1;unused<=n;)
		{
			for(r=unused;r<=n && a[r]!=cur;r++);
			nex=r;
			for(int i=cur+1;i<nex;i++) hav[a[i]]++;
			int pp=-1,exi=0;
			if(cur!=1 && hav[1]%2==0) pp=1;
			else if(cur!=2 && hav[2]%2==0) pp=2;
			else if(cur!=3 && hav[3]%2==0) pp=3;
			if(hav[1]&1) exi=1;
			else if(hav[2]&1) exi=2;
			else if(hav[3]&1) exi=3;
//			printf("nex = %d\n",nex);
			if(pp!=-1)
			{
				for(int i=unused;i<nex;i++)
				{
					if(a[i]==pp) addop(1,cursta);
					else addop(1,((cursta-1)^1)+1);
				}
				addop(1,cursta);
				if(exi)
				{
					cursta=((cursta-1)^1)+1,cur=exi;
					if(cur==1) hav[1]=1,hav[2]=hav[3]=0;
					else if(cur==2) hav[2]=1,hav[1]=hav[3]=0;
					else if(cur==3) hav[3]=1,hav[1]=hav[2]=0;
					unused=nex+1;
				}
				else
				{
					if(nex==n) break;
					else unused=nex+2,cur=a[nex+1];
					if(cur==1) hav[1]=1,hav[2]=hav[3]=0;
					else if(cur==2) hav[2]=1,hav[1]=hav[3]=0;
					else if(cur==3) hav[3]=1,hav[1]=hav[2]=0;
				}
			}
			else
			{
				exi=-1;
				for(int i=unused,added=0;i<nex;i++)
				{
					if(hav[a[i]]&1) hav[a[i]]--,addop(1,cursta),added++,exi=a[i];
					else
					{
						if(added==1) addop(1,((cursta-1)^1)+1);
						else if(exi==a[i]) addop(1,cursta);
						else addop(1,((cursta-1)^1)+1);
					}
				}
				addop(1,cursta),addop(2,1,2);
				if(cur==1) hav[2]=hav[3]=1,hav[1]=0,cur=((exi==2)?3:2);
				else if(cur==2) hav[1]=hav[3]=1,hav[2]=0,cur=((exi==1)?3:1);
				else if(cur==3) hav[1]=hav[2]=1,hav[3]=0,cur=((exi==1)?2:1);
				unused=nex+1;
			}
//			printf("cur = %d unused = %d\n",cur,unused);
		}
		printf("%d\n",op);
		for(int i=1;i<=op;i++)
		{
			if(typ[i]==1) printf("1 %d\n",s1[i]);
			else printf("2 %d %d\n",s1[i],s2[i]);
		}
	}
}
//namespace subtask3
//{
//	void solve()
//	{
//		
//	}
//}
int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=rd();
	for(int Case=1;Case<=T;Case++)
	{
		n=rd(),m=rd(),k=rd(),op=0;
		for(int i=1;i<=m;i++) a[i]=rd();
		if(T%10==1) subtask1::solve();
		else if(T%10==2) subtask2::solve();
//		else if(T%10==3) subtask3::solve();
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
