#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e6+10;
int a[N];
struct Node
{
	int op,s1,s2;
}ans[N*2];
int q[N],f,b;
bool vis[N];
int p[1010],pos[N];
int top[1010],bg[N];
bool v[N];
void solve()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=m;++i)scanf("%d",&a[i]);
	for(int i=1;i<=k;++i)vis[i]=0;
	int tot=0;
	if(n==2)
	{
		f=0;b=1;
		for(int i=1;i<=m;++i)
		{
			if(!vis[a[i]])
			{
				vis[a[i]]=1;
				q[++f]=a[i];
				ans[++tot].op=1;
				ans[tot].s1=1;
			}
			else 
			{
				vis[a[i]]=0;
				if(q[f]==a[i])
				{
					--f;
					ans[++tot].op=1;
					ans[tot].s1=1;
				}
				else
				{
					ans[++tot].op=1;
					ans[tot].s1=2;
					ans[++tot].op=2;
					ans[tot].s1=1;
					ans[tot].s2=2;
					++b;
				}
			}
		}
		printf("%d\n",tot);
		for(int i=1;i<=tot;++i)
		{
			printf("%d %d",ans[i].op,ans[i].s1);
			if(ans[i].op==2)printf(" %d",ans[i].s2);
			puts("");
		}
		return;
	}
	for(int i=m;i>=1;--i)
	{
		if(p[a[i]])
		{
			pos[i]=p[a[i]];
			p[a[i]]=0;
		}
		else p[a[i]]=i;
	}	
	for(int i=1;i<=n;++i)top[i]=0;
	int s=1,j;
	for(int i=1;i<=m;++i)
	{
		if(pos[i])
		{
			j=1;
			while(pos[top[j]]>pos[i]&&j+1<n)++j;
			if(j>=n)
			{
				j=s;
				++s;
				if(s>=n)s=1;
				v[pos[i]]=1;
			}
			top[j]=a[i];
			ans[++tot].op=1;
			ans[tot].s1=j;
			bg[pos[i]]=j;
		}
		else
		{
			if(v[i])
			{
				ans[++tot].op=1;
				ans[tot].s1=bg[i];
			}
			else
			{
				ans[++tot].op=1;
				ans[tot].s1=n;
				ans[++tot].op=2;
				ans[tot].s1=n;
				ans[tot].s2=bg[i];
			}
		}
	}
	printf("%d\n",tot);
	for(int i=1;i<=tot;++i)
	{
		printf("%d %d",ans[i].op,ans[i].s1);
		if(ans[i].op==2)printf(" %d",ans[i].s2);
		puts("");
	}
}
int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T;
	scanf("%d",&T);
	while(T--)
	{
		solve();
	}
	return 0;
}
