//Private Eye, dancing with the wind.
#include<bits/stdc++.h>
using namespace std;

#define MAXN 305
#define MAXN2 2000005
int a[MAXN2],opt[MAXN2<<1],s1[MAXN2<<1],s2[MAXN2<<1];

namespace Subtask1{
	int sta[MAXN],cnt[MAXN];
	void solve()
	{
		memset(sta,0,sizeof(sta));
		memset(cnt,0,sizeof(cnt));
		int n,m,k,ans=0;
		scanf("%d%d%d",&n,&m,&k);
		while(m--)
		{
			int x,num;
			scanf("%d",&x);num=(x+1)/2;
			if(!cnt[num]) sta[num]=x,cnt[num]++,opt[++ans]=1,s1[ans]=num;
			else if(sta[num]==x)
			{
				opt[++ans]=1,s1[ans]=n;
				opt[++ans]=2,s1[ans]=num,s2[ans]=n;
				if(cnt[num]==1) cnt[num]=sta[num]=0;
				else cnt[num]--,sta[num]=2*num+1-sta[num];
			}
			else if(cnt[num]==1)
			{
				opt[++ans]=1,s1[ans]=num;
				cnt[num]++;
			}
			else
			{
				opt[++ans]=1,s1[ans]=num;
				cnt[num]--;
			}
		}
		printf("%d\n",ans);
		for(int i=1;i<=ans;i++)
		{
			printf("%d %d",opt[i],s1[i]);
			if(opt[i]==2) printf(" %d",s2[i]);
			putchar('\n');
		}
	}
}

namespace Subtask3{
	deque<int> q[4];
	int n,m,k,ans,qwq;
	inline void dfs(int x)
	{
		if(qwq) return;
		for(int i=1;i<=n;i++)
			for(int j=i+1;j<=n;j++)
				if(!q[i].empty() and !q[j].empty())
					if(q[i].front()==q[j].front())
					{
						int s=q[i].front();
						q[i].pop_front(),q[j].pop_front();
						opt[++ans]=2,s1[ans]=i,s2[ans]=j,dfs(x);
						if(qwq) return;
						ans--,q[i].push_front(s),q[j].push_front(s);
					}
		if(x==m+1)
		{
			for(int i=1;i<=n;i++)
				if(!q[i].empty()) return;
			qwq=1;return;
		}
		for(int i=1;i<=n;i++)
		{
			opt[++ans]=1,s1[ans]=i;
			if(!q[i].empty())
			{
				if(q[i].back()==a[x])
				{
					q[i].pop_back();
					dfs(x+1);if(qwq) return;
					q[i].push_back(a[x]);
				}
				else
				{
					q[i].push_back(a[x]);
					dfs(x+1);if(qwq) return;
					q[i].pop_back();
				}
			}
			else
			{
				q[i].push_back(a[x]);
				dfs(x+1);if(qwq) return;
				q[i].pop_back();
			}
			ans--;
		}
	}
	void solve()
	{
		ans=qwq=0;
		scanf("%d%d%d",&n,&m,&k);
		for(int i=1;i<=m;i++)
			scanf("%d",&a[i]);
		dfs(1);
		printf("%d\n",ans);
		for(int i=1;i<=ans;i++)
		{
			printf("%d %d",opt[i],s1[i]);
			if(opt[i]==2) printf(" %d",s2[i]);
			putchar('\n');
		}
	}
}

int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T;
	scanf("%d",&T);
	if(T==1001) while(T--) Subtask1::solve();
	while(T--) Subtask3::solve();
}