#include<bits/stdc++.h>
using namespace std;
#define ll int
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll rd(){
	ll x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}
#define d rd()
ll n,m,col;
ll a[2000010];
ll id[1010];
deque<ll>q[310];
deque<ll>Q[310];
ll res;
struct node{
	ll o,x,y;
}ans[4000010];
void ch(){
	ll cur=0;bool fl=0;
	f(i,1,n)while(!Q[i].empty())Q[i].pop_front();
	f(i,1,res){
		if(ans[i].o==1){
			cur++;ll x=ans[i].x;
			if(Q[x].empty())Q[x].push_front(a[cur]);
			else if(Q[x].front()==a[cur])Q[x].pop_front();
			else Q[x].push_front(a[cur]);
		}if(ans[i].o==2){
			ll x=ans[i].x,y=ans[i].y;
			if(Q[x].empty()||Q[y].empty()){fl=1;break;}
			if(Q[x].back()!=Q[y].back()){fl=1;break;}
			Q[x].pop_back(),Q[y].pop_back();
		}
	}f(i,1,n)if(!Q[i].empty())fl=1;
	if(!fl)puts("ok!");else puts("WAAAAAAAAAaAAAA");
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	ll T=d;while(T--){
		n=d,m=d,col=d;res=0;
		f(i,1,m)a[i]=d;
		if(col==n*2-2){
			f(i,1,col)id[i]=(i+1)/2;
			f(i,1,m){
				ll x=id[a[i]];
				if(q[x].empty())q[x].push_front(a[i]),ans[++res]={1,x,0};
				else if(q[x].size()==1){
					if(q[x].front()==a[i])ans[++res]={1,x,0},q[x].pop_front();
					else ans[++res]={1,x,0},q[x].push_front(a[i]);
				}else{
					if(a[i]==q[x].front())ans[++res]={1,x,0},q[x].pop_front();
					else ans[++res]={1,n,0},ans[++res]={2,x,n},q[x].pop_back();
				}
			}
//			ch();
			printf("%d\n",res);
			f(i,1,res){
				if(ans[i].o==1)printf("1 %d\n",ans[i].x);
				else printf("2 %d %d\n",ans[i].x,ans[i].y);
			}continue;
		}
	}
	return 0;
}
/*
1
2 4 2
1 2 1 2
*/
