#include<bits/stdc++.h>
using namespace std;
int t,n,m,k;
int a[2000005];
vector<int> s[305];
int siz[305];
struct sta{
	int top,tail;
}now[305];
int id=0;
int check(int idx,int x){
	for(int i=0;i<n;i++){
		bool flag=0;
		for(int j=x;j<x+n&&j<m;j++){
			if(a[j]==now[idx].top)flag=1;
		}
		if(flag==0){
			now[idx].top=a[x];
			s[idx].push_back(a[x]);
			return idx;
		}
		else{
			idx++;
			idx%=n;
		}
	}
	return idx;
}
int num=0;
struct query{
	int id,x,y;
}ans[2000005];
int vis[650];
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		num=0;
		scanf("%d%d%d",&n,&m,&k);//n stack_num
		for(int i=0;i<m;i++){
			scanf("%d",&a[i]);
		}
		for(int i=0;i<m;i++){
			
			bool f=0;
			//top del
			for(int j=0;j<n;j++){
			
				if(a[j]==now[j].top){
					ans[num].id=1;
					ans[num].x=j+1;
					num++;
					s[j][siz[j]-1]=0;
					if(siz[j-1]==0){
						now[j].top=0;
						s[j][0]=0;
						id=j;
					}
					else{
						now[j].top=s[j][siz[j]-2];
					}
					siz[j]--;
					f=1;
					break;
				}
			}
			if(f==1)continue;
			for(int j=0;j<k;j++){
				vis[k]=-1;
			}
			//put
			if(now[id].top==0){
				now[id].top=a[i];
				s[id].push_back(a[i]);
				siz[id]++;
				ans[num].id=1;
				ans[num].x=id+1;
				num++;
				id++;
				id%=n;
			}
			else{
				id=check(id,i);
				ans[num].id=1;
				ans[num].x=id+1;
				num++;
				id++;
			}
			bool end=0;//main end
			//tail del
			while(1){
				bool flag=0;
				for(int j=0;j<n;j++){
					if (now[j].top!=0)end=1;
					if(siz[j]!=0&&vis[s[j][now[j].tail]]!=-1){
						int idx1=vis[now[j].tail];
						ans[num].id=2;
						ans[num].x=idx1+1;
						ans[num].y=j+1;
						num++;
						if(now[idx1].tail==now[idx1].top){
							s[idx1][0]=0;
							siz[idx1]=0;
							now[idx1].top=0;
						}
						else{
							now[idx1].tail++;
						}
						if(now[j].tail==now[j].top){
							s[j][0]=0;
							siz[j]=0;
							now[j].top=0;
							id=j;
						}
						else{
							now[j].tail++;
						}
						flag=1;
					}
					else {
						if(siz[j]!=0){
							vis[s[j][now[j].tail]]=j;
						}
					}
				}
				if(flag==0)break;
			}
			if(end){
				printf("%d\n",num);
				for(int j=0;j<num;j++){
					if(ans[j].id==1){
						printf("1 %d\n",ans[j].x);
					}
					else printf("2 %d %d\n",ans[j].x,ans[j].y);
				}
				for(int j=0;j<n;j++){
					siz[j]=0;
					now[j].top=0;
					now[j].tail=0;
				}
				break;
			}
		}
	}
	return 0;
}
/*
1
2 4 2
1 2 1 2
*/
/*
1
3 10 5
1 2 3 4 5 2 3 4 5 1
*/
/*
15
1 1
1 1
1 1
1 1
1 1
1 2
1 2
1 2
1 2
1 3
2 1 3
2 1 2
2 1 2
2 1 2
2 1 2
*/