#include<bits/stdc++.h>
#define int long long
#define F(i,j,k) for(register int i=j,_End=k;i<=_End;i++)
#define D(i,j,k) for(register int i=j,_End=k;i>=_End;i--)
#define N 305
using namespace std;

inline void ri(int &x)
{
	x=0;
	char c=getchar();
	while(c<48||c>57)	c=getchar();
	while(c>47&&c<58)	x=x*10+c-48,c=getchar();
}

int T,n,m,k,q,tmp,opt,ct,pi[2000005];

deque<int> st[N];

signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	ri(T);
	if(T==1001)
	{
		F(t,1,T)
		{
			opt=0;
			F(i,0,300)	st[i].clear();
			ri(n),ri(m),ri(k);
			F(i,1,m)
			{
				ri(pi[i]),q=(pi[i]+1)/2;
				if(st[q].empty())
				{
					opt++;
					st[q].push_back(pi[i]);
				}
				else if(st[q].back()==pi[i])
				{
					opt++;
					st[q].pop_back();
				}
				else if(st[q].front()==pi[i])
				{
					opt++;
					opt++;
					st[q].pop_front();
				}
				else
				{
					opt++;
					st[q].push_back(pi[i]);
				}
			}
			printf("%lld\n",opt);
			F(i,0,300)	st[i].clear();
			F(i,1,m)
			{
				q=(pi[i]+1)/2;
				if(st[q].empty())
				{
					printf("1 %lld\n",q);
					st[q].push_back(pi[i]);
				}
				else if(st[q].back()==pi[i])
				{
					printf("1 %lld\n",q);
					st[q].pop_back();
				}
				else if(st[q].front()==pi[i])
				{
					printf("1 %lld\n",n);
					printf("2 %lld %lld\n",q,n);
					st[q].pop_front();
				}
				else
				{
					printf("1 %lld\n",q);
					st[q].push_back(pi[i]);
				}
			}
		}
	}
/*	if(T==1002)
	{
		F(t,1,T)
		{
			F(i,0,300)	st[i].clear();
			ri(n),ri(m),ri(k);
			F(i,0,m)	pi[i]=0;
			F(i,1,m)
			{
				ri(pi[i]);
				if(pi[i]==pi[i-1])
				{
					pi[i-1]=-1;
					pi[i]=-2;
				}
			}
			F(i,1,m)
			{
				if(pi[i]<0)
				{
					printf("1 %lld\n",1);
					continue;
				}
				if(pi[i]==2)
				{
					if(st[1].empty())
					{
						printf("1 %lld\n",1);
						st[1].push(p);
					}
					else
					{
						printf("1 %lld\n",1);
						st[1].pop_back();
					}
					continue;
				}
				if(pi[i]==3)
				{
					if(ct==2)
					{
						if(!st[2].empty())
						{
							printf("1 %lld\n",1);
							printf("2 1 2\n");
						}
						else
						{
							
						}
						continue;
					}
					if(st[2].empty())
					{
						printf("1 %lld\n",2);
						st[2].push(p);
					}
					else
					{
						printf("1 %lld\n",2);
						st[2].pop_back();
					}
					continue;
				}
				if(pi[i]==1)
				{
					tmp=i+1;
					ct=0;
					while(tmp<=m&&pi[tmp]!=1)
					{
						if(p[i]<0)
						{
							continue;
						}
						if(p[i]==2)
						{
							ct=2;
							continue;
						}
						if(p[i]==3)
						{
							ct=1;
							continue;
						}
					}
					printf("1 %lld\n",ct);
					pi[tmp]=0;
				}
				if(pi[i]==0)
				{
					printf("1 %lld\n",ct);
					ct=0;
				}
			}
		}
	}*/
	return 0;
}
