#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
struct node {
	int x,y;
} ops[N];
int n,m,k;
int a[N];
int cnt,kind[N];
int under_w[N];
int on_w[N];
deque<int> q[350];
void putout() {
	cout<<cnt<<endl;
	for(int i=1; i<=cnt; i++)
		if(kind[i]==1)
			cout<<kind[i]<<" "<<ops[i].x<<endl;
		else
			cout<<kind[i]<<" "<<ops[i].x<<" "<<ops[i].y<<endl;
}
void doo(int i) {
	if(i>m) {
		putout();
		return ;
	}
	if(on_w[a[i]]) {
		int k=on_w[a[i]];
		q[k].pop_back();
		kind[++cnt]=1;
		ops[cnt].x=k;
		ops[cnt].y=0;
		on_w[a[i]]=0;
		if(q[k].size())
			on_w[q[k].back()]=k;
		doo(i+1);
		return ;
	}
	if(under_w[a[i]]) {
		int k=under_w[a[i]];
		for(int j=1; j<=n; j++)
			if(q[j].empty()) {
				q[k].pop_front();
				kind[++cnt]=1;
				ops[cnt].x=j;
				ops[cnt].y=0;
				kind[++cnt]=2;
				ops[cnt].x=k;
				ops[cnt].y=j;
				under_w[a[i]]=0;
				if(q[k].size())
					under_w[q[k].front()]=k;
				doo(i+1);
				return ;
			}
	}
	for(int j=1; j<=n; j++)
		if(q[j].empty()) {
			q[j].push_back(a[i]);
			under_w[a[i]]=j;
			on_w[a[i]]=j;
			kind[++cnt]=1;
			ops[cnt].x=j;
			ops[cnt].y=0;
			doo(i+1);
			return ;
		}
	int ne=on_w[a[i+1]];
	for(int j=1; j<=n; j++)
		if(j!=ne) {
			q[j].push_back(a[i]);
			on_w[a[i]]=j;
			kind[++cnt]=1;
			ops[cnt].x=j;
			ops[cnt].y=0;
			doo(i+1);
			return ;
		}
}

signed main() {
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T;
	cin>>T;
	while(T--) {
		cnt=0;
		cin>>n>>m>>k;
		for(int i=1; i<=m; i++)
			cin>>a[i];
		doo(1);
	}

	return 0;
}
/*
1
2 4 2
1 2 1 2
*/
