/*
after dusk passed,
there is a starry sky.
*/
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
#define len(a) (int)a.size()
using namespace std;
const int N=310,M=2*1e6+100;
int T,n,m,k,a[M],cnt[N],in[M],to[M],last[N];
int head[N],tail[N],pre[M],suc[M],sz[N],tp[N];
vector <tuple<int,int,int> > ans;
inline int read()
{
	int f=1,x=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
void upd(int pos)
{
	if (sz[pos]<=1) return;
	tp[pos]=(to[tail[pos]]<to[pre[tail[pos]]]);
}
void add(int pos,int v)
{
	ans.emplace_back(1,pos,0);
	if (sz[pos]==0)
	{
		head[pos]=tail[pos]=v;
		sz[pos]++;return;
	}
	pre[v]=tail[pos];suc[tail[pos]]=v;
	tail[pos]=v;sz[pos]++;
	upd(pos);
}
void del_back(int pos)
{
	ans.emplace_back(1,pos,0);
	if (sz[pos]==1)
	{
		head[pos]=tail[pos]=0;
		sz[pos]--;return;
	}
	tail[pos]=pre[tail[pos]];
	suc[tail[pos]]=0;
	sz[pos]--;upd(pos);
}
void del_front(int pos)
{
	ans.emplace_back(2,pos,n);
	if (sz[pos]==1)
	{
		head[pos]=tail[pos]=0;
		sz[pos]--;return;
	}
	head[pos]=suc[head[pos]];
	pre[head[pos]]=0;
	sz[pos]--;upd(pos);
}
signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	while (T--)
	{
		n=read();m=read();k=read();
		for (int i=1;i<=m;i++) a[i]=read();
		memset(cnt,0,sizeof(cnt));
		for (int i=1;i<=m;i++)
		{
			cnt[a[i]]++;
			if (cnt[a[i]]&1)
			{
				in[i]=1;
				last[a[i]]=i;
			}
			else
			{
				in[i]=-1;
				to[last[a[i]]]=i;
				to[i]=last[a[i]];
			}
		}
		ans.clear();
		memset(tp,-1,sizeof(tp));
		for (int i=1;i<=m;i++)
		{
			if (in[i]==1)
			{
				bool bl=1;int MAX=0,wh;
				for (int j=1;j<n;j++) if (sz[j])
				{
					if ((sz[j]==1||tp[j]==0)&&to[tail[j]]<to[i]&&to[tail[j]]>MAX)
					{
						MAX=to[tail[j]];
						wh=j;bl=0;
					}
				}
				if (!bl)
				{
					add(wh,i);
					continue;
				}
				int MIN=inf;bl=1;
				for (int j=1;j<n;j++) if (sz[j])
				{
					if ((sz[j]==1||tp[j]==1)&&to[tail[j]]>to[i]&&to[tail[j]]<MIN)
					{
						MIN=to[tail[j]];
						wh=j;bl=0;
					}
				}
				if (!bl)
				{
					add(wh,i);
					continue;
				}
				bl=1;
				for (int j=1;j<n;j++) if (!sz[j])
				{
					add(j,i);bl=0;
					break;
				}
				// if (bl) return 0;
				// assert(!bl);
			}
			else
			{
				bool bl=1;
				for (int j=1;j<n;j++) if (sz[j])
				{
					if (a[tail[j]]==a[i]){bl=0;del_back(j);break;}
					if (a[head[j]]==a[i]){bl=0;ans.emplace_back(1,n,0);del_front(j);break;}
				}
				// assert(!bl);
				// if (bl)
				// {
				// 	printf("%d\n",i);
				// 	return 0;
				// }
			}
			// printf("%d\n",accumulate(sz+1,sz+n,0));
		}
		// for (int i=1;i<=n;i++) assert(sz[i]==0);
		printf("%d\n",len(ans));
		for (auto it:ans)
		{
			int op=get<0>(it);
			printf("%d %d",op,get<1>(it));
			if (op==2) printf(" %d\n",get<2>(it));
			else printf("\n");
		}
	}
}