#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int s[N],f[N],a[N],g[N];
int tem;
int emp;
int up[N];
int down[N];
int n,m,k;
struct node{
	int id;
	int x,y;
}e[N];
int ans;
void miao(){
	for(int i = 1;i <= m;i++){
		if(!f[a[i]] && !g[a[i]]){
			e[++ans].id = 1;
			e[ans].x = tem;
			f[a[i]] = tem;
			up[tem] = a[i];
			if(!s[tem]) g[a[i]] = tem,down[tem] = a[i];
			s[tem]++;
			emp = emp%n + 1;
			tem = tem%n + 1;
			continue;
		}
		if(f[a[i]] && a[i] == up[f[a[i]]]){
			e[++ans].id = 1;
			e[ans].x = f[a[i]];
			s[f[a[i]]]--;
			if(s[f[a[i]]] == 0) emp = f[a[i]],up[f[a[i]]] = 0,down[f[a[i]]] = 0;
			else up[f[a[i]]] = down[f[a[i]]];
			f[a[i]] = 0;
			continue;
		}
		if(g[a[i]] && a[i] == down[g[a[i]]]){
			e[++ans].id = 2;
			e[ans].x = g[a[i]];
			for(int i = 1;i <= n;i++){
				if(!s[i]){
					emp = i;
					break;
				}
			} 
			e[ans].y = emp;
			s[g[a[i]]] = 0;
			if(!s[g[a[i]]]) emp = g[a[i]],down[g[a[i]]] = 0,up[g[a[i]]] = 0;
			else down[g[a[i]]] = up[g[a[i]]];
			g[a[i]] = 0;
			continue;
		}
	}
	cout << ans << endl;
	for(int i = 1;i <= ans;i++){
		if(e[i].id == 1) cout << "1" << " " << e[i].x << endl;
		else cout << "2" << " " << e[i].x << " " << e[i].y << endl;
	}
}
int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T;
	cin >> T;
	while(T--){
		memset(s,0,sizeof(s));
		memset(f,0,sizeof(f));
		memset(g,0,sizeof(g));
		memset(a,0,sizeof(a));
		memset(e,0,sizeof(e));
		memset(up,0,sizeof(up));
		memset(down,0,sizeof(down));
		cin >> n >> m >> k;
		for(int i = 1;i <= m;i++) cin >> a[i];
		tem = 1;
		emp = 1;
		ans = 0;
		miao();
	}
	return 0;
}
