#include<cstdio>
#include<cstring>
#include<algorithm>
#include<deque>
using namespace std;
const int N=2e6+10,M=300;
bool mem1;
int sk[M],id[N],las[N],n,m,k,a[N],nex[N],pos[N],opt[N],tot,ans[N][3],tmp[N][3],len[N],st[N],ed[N];
deque<int>stk[M];bool ok;
void dfs(int now,int res,int cnt)
{
	if(ok) return ;
	if(now>m&&res==0)
	{
		ok=true;tot=cnt;
		for(int i=1;i<=cnt;i++) ans[i][0]=tmp[i][0],ans[i][1]=tmp[i][1],ans[i][2]=tmp[i][2];
		return ;
	}
	if(now>m) return ;
	for(int i=1;i<=n;i++)
	{
		tmp[cnt+1][0]=1;
		tmp[cnt+1][1]=i;
		int p=stk[i].size();
		if(p&&stk[i][p-1]==a[now]) 
		{
			int t=stk[i][p-1];
//			tmp[cnt+1][0]=1;
//			tmp[cnt+1][1]=i;s
			stk[i].pop_back();
			dfs(now+1,res-1,cnt+1);
			stk[i].push_back(t);
		}
		else 
		{
			if(!p)
			{
				for(int j=1;j<=n;j++)
				{
					int pp=stk[j].size();
//					if(now==3) printf("%d %d\n",p,pp);
					if(pp&&stk[j][pp-1]==a[now])
					{
						int tt=stk[j][0];
	//					tmp[cnt+1][0]=1;
	//			        tmp[cnt+1][1]=i;
				        tmp[cnt+2][0]=2;
				        tmp[cnt+2][1]=i;
				        tmp[cnt+2][2]=j;
				        stk[j].pop_front();
				        dfs(now+1,res-1,cnt+2);
				        stk[j].push_front(tt);
					}
				}	
			}
			stk[i].push_back(i);
			dfs(now+1,res+1,cnt+1);
			stk[i].pop_back();
		}
	}
}
void solve()
{
	scanf("%d%d%d",&n,&m,&k);tot=m;ok=false;
	for(int i=1;i<=m;i++) len[i]=0,scanf("%d",&a[i]);
	for(int i=1;i<=k;i++) pos[k]=0;int cnt=0,top=0;
	for(int i=1;i<=n;i++) sk[++top]=i;
	for(int i=1;i<=m;i++)
	{
		int j=pos[a[i]],k=1;
		if(top) id[i]=sk[top--];
		else id[i]=1;
		if(pos[a[i]])
		{
			while(i+k<=m&&a[i+k]==a[j+k]) id[j+k]=id[j],id[i+k]=id[i],k++;
			len[i+k-1]=k;
			st[i+k-1]=id[j],ed[i+k-1]=id[i];
			sk[++top]=id[i];
			tot+=k;pos[a[i]]=i;
			i=i+k-1;
		} 
		else pos[a[i]]=i;
	}
	printf("%d\n",tot);
	for(int i=1;i<=m;i++)
	{
		printf("1 %d\n",id[i]);
		if(!len[i]) continue;
		for(int j=1;j<=len[i];j++) printf("2 %d %d\n",st[i],ed[i]);
	}
	/*for(int i=1;i<=n;i++) stk[i].clear();
	dfs(1,0,0);printf("%d\n",tot);
	for(int i=1;i<=tot;i++) 
	    if(ans[i][0]==1) printf("%d %d\n",ans[i][0],ans[i][1]);
	    else printf("%d %d %d\n",ans[i][0],ans[i][1],ans[i][2]);*/
}
bool mem2;
int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
//    printf("%.6lf\n",(abs(&mem1-&mem2))/8.0/1024/1024);
	int T;scanf("%d",&T);while(T--) solve();
	return 0;
}