#include<bits/stdc++.h>
using namespace std;
const int N=2000005;
const int K=605;
int T,n,m,k,now,tot;
int a[N];
int s[K][K];
int h[K],t[K],col[K];
void step1(int pos)
{
	cout<<"1 "<<pos<<endl;
}
void step2(int pos1,int pos2)
{
	cout<<"2 "<<pos1<<" "<<pos2<<endl;
}
int DelTop(int pos)
{
	for(int i=1;i<=now;++i) {
		if(s[i][t[i]]==a[pos]) {
			--t[i];
			step1(i);
			return 1;
		}
	}
	return 0;
}
signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	cin>>T;
	while(T--) {
		tot=0;
		cin>>n>>m>>k;
		cout<<m<<endl;
		for(int i=1;i<=n;++i) {
			h[i]=1;t[i]=0;
		}
		for(int i=1;i<=m;++i) {
			cin>>a[i];
		}
		for(int i=1;i<=m;++i) {
			int op=DelTop(i);
			if(op==1) continue;
			if(now<n) {
				++now;
				++t[now];
				s[now][1]=a[i];
				step1(now);
			}
			else {
				int id=1;
				for(int j=2;j<=n;++j) {
					if(t[j]-h[j]>t[id]-h[id]) {
						id=j;
					}
				}
				++t[id];
				s[id][t[id]]=a[i];
				step1(id);
			}
			for(int i=1;i<=m;++i) {
				col[i]=0;
			}
			vector<int> p[K];
			for(int i=1;i<=n;++i) {
				++col[s[i][1]];
				p[s[i][1]].push_back(i);
			}
			for(int ii=1;ii<=k;++ii) {
				if(col[ii]>1) {
					for(int jj=0;jj<p[col[ii]].size();jj+=2) {
						h[p[col[ii]][jj]]++;
						h[p[col[ii]][jj+1]]++;
						step2(p[col[ii]][jj],p[col[ii]][jj+1]);
					}
				}
			}
		}
	}
	return 0;
}
