#include <bits/stdc++.h>
using namespace std;
class Stack {
	int tp=-1,btm=0;
	vector<int> a;
	
public:
	Stack() {
		a.resize(1);
	}
	
	void push(int x) {
		if(tp==a.size()-1)
			a.push_back(x);
		else
			a[tp+1]=x;
		tp++;
	}
	
	void pop_top() {
		tp--;
	}
	
	void pop_btm() {
		btm++;
	}
	
	int top() {
		if(tp>=btm&&tp!=-1)
			return a[tp];
		else
			return 0;
	}
	
	int bottom() {
		if(btm<=tp&&btm!=-1)
			return a[btm];
		else
			return 0;
	}
	
	int len() {
		return tp-btm+1;
	}
};
string toString(int x) {
	string s;
	while(x>0) {
		s.push_back(x%10+'0');
		x/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int main() {
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T;
	cin>>T;
	while(T--) {
		int n,m,k;
		cin>>n>>m>>k;
		vector<int> a(m+1);
		for(int i=1;i<=m;i++)
			cin>>a[i];
		vector<Stack> s(n+1);
		vector<int> tb(k+1);
		vector<string> op;
		for(int i=1;i<=m;i++) {
			for(int i=1;i<=k;i++)
				if(tb[i]>=2) {
					vector<int> temp;
					for(int j=1;j<=n;j++)
						if(s[j].bottom()==i)
							temp.push_back(j);
					for(int j=0;j*2+1<temp.size();j++) {
						s[temp[j*2]].pop_btm(),s[temp[j*2+1]].pop_btm();
						op.push_back("2 "+toString(temp[j*2])+" "+toString(temp[j*2+1]));
						tb[i]-=2;
					}				
				}
			bool flag=false;
			for(int j=1;j<=n;j++)
				if(s[j].top()==a[i]) {
					s[j].pop_top();
					op.push_back("1 "+toString(j));
					flag=true;
					break;
				}
			if(flag)
				continue;
			int minlen=2e9,mini=0;
			for(int j=1;j<=n;j++)
				if(s[j].len()<minlen) {
					mini=j;
					minlen=s[j].len();
				}
			s[mini].push(a[i]);
			op.push_back("1 "+toString(mini));
			if(s[mini].len()==1)
				tb[a[i]]++;
			continue;
		}
		cout<<op.size()<<endl;
		for(auto str:op) {
			cout<<str<<endl;
		}
	}
	return 0;
}
