///I LOVE CCF !!!   PLEASE LET ME PASS !!!!    
#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN=2000005;
int n,m,k,T;
int card[MAXN],op[MAXN*2][5],oprt;
///I LOVE CCF !!!   PLEASE LET ME PASS !!!!    
struct Queue {
	int l,r,num[MAXN/2];
	void add(int x) {
		num[r++]=x;
	}
	void popl() {
		l++;
	}
	void popr() {
		r--;
	}
///I LOVE CCF !!!   PLEASE LET ME PASS !!!!    
	int front() {
		return num[l];
	}
	int back() {
		return num[r-1];
	}
	void clear() {
		l=r=0;
	}
	int findit(int x) {
		for(int i=l; i<r; i++)
			if(x==num[i])return i;
		return 0;
	}
	int lengh() {
		return r-l;
	}
} q[305];
///I LOVE CCF !!!   PLEASE LET ME PASS !!!!    
bool check() {
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			if(i==j||q[i].lengh()==0||q[j].lengh()==0)continue;
			if(q[i].front()==q[j].front()) {
				op[oprt][0]=2;
				op[oprt][1]=i;
				op[oprt][2]=j;
				q[i].popl();
				q[j].popl();
				oprt++;
				return 1;
			}
		}
	}
	return 0;
}
///I LOVE CCF !!!   PLEASE LET ME PASS !!!!    
void solve(int x) {
	for(int i=1; i<=n; i++) {
		if(q[i].lengh()==0)continue;
		if(q[i].back()==x) {
			op[oprt][0]=1;
			op[oprt][1]=i;
			q[i].popr();
			oprt++;
			return ;
		}
	}
///I LOVE CCF !!!   PLEASE LET ME PASS !!!!    
	for(int i=1; i<=n; i++) {
		if(q[i].lengh()==0)continue;
		if(q[i].front()==x) {
			for(int j=1;j<=n;j++)
				if(q[j].lengh()==0){
					op[oprt][0]=1;
					op[oprt][1]=j;
					q[j].add(x);
					oprt++;
					while(check());
					return ;
				}
		}
	}
///I LOVE CCF !!!   PLEASE LET ME PASS !!!!    
///I LOVE CCF !!!   PLEASE LET ME PASS !!!! 
	bool flag=0;
	for(int i=1;i<=n;i++){
		if(q[i].lengh()==0){
			if(flag==1){
				op[oprt][0]=1;
				op[oprt][1]=i;
				q[i].add(x);
				oprt++;
				return ;
			}
			flag=1;
		}
	}  
///I LOVE CCF !!!   PLEASE LET ME PASS !!!!    
///I LOVE CCF !!!   PLEASE LET ME PASS !!!! 
	for(int i=1; i<=n; i++) {
		if(q[i].lengh()==0)continue;
		int h=q[i].findit(x);
		if(!h){
			op[oprt][0]=1;
			op[oprt][1]=i;
			q[i].add(x);
			oprt++;
		}
	} 
}
///I LOVE CCF !!!   PLEASE LET ME PASS !!!!    
int main() {
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	scanf("%d",&T);
///I LOVE CCF !!!   PLEASE LET ME PASS !!!!    
	while(T--) {
		oprt=0;
		scanf("%d%d%d",&n,&m,&k);
		for(int i=1; i<=n; i++) q[i].clear();
		for(int i=1; i<=m; i++)scanf("%d",&card[i]);
		for(int i=1; i<=m; i++)
			solve(card[i]);
///I LOVE CCF !!!   PLEASE LET ME PASS !!!!    
		printf("%d\n",oprt);
		for(int i=0; i<oprt; i++) {
			printf("%d ",op[i][0]);
			if(op[i][0]==1)
				printf("%d\n",op[i][1]);
			else printf("%d %d\n",op[i][1],op[i][2]);
		}
	}
	return 0;
}
///I LOVE CCF !!!   PLEASE LET ME PASS !!!!    