#include<bits/stdc++.h>
using namespace std;
const int N=605;
const int M=2e6+5;

vector<tuple<int,int,int>>ans;
set<int>id[4];
vector<int>b[N];
int n,m,k,a[M],x[N],y[N];
void push(int u,int v) {
//	cerr<<1<<' '<<u<<endl;
	ans.emplace_back(1,u,v);
	id[b[u].size()].erase(u);
	if (!b[u].empty()&&b[u].back()==v) {
		x[v]=y[v]=0;
		b[u].pop_back();
	} else {
		b[u].emplace_back(v);
		x[v]=u,y[v]=b[u].size();
	}
	id[b[u].size()].insert(u);
}
void pop(int u,int v) {
	int pos=*id[0].begin();
//	cerr<<1<<' '<<pos<<endl;
//	cerr<<2<<' '<<pos<<' '<<u<<endl;
	ans.emplace_back(1,pos,v);
	ans.emplace_back(2,pos,u);
	id[b[u].size()].erase(u);
	for (int i:b[u]) {
		y[i]--;
	}
	x[v]=y[v]=0;
	for (int i=0;i+1<(int)b[u].size();i++) {
		b[u][i]=b[u][i+1];
	}
	b[u].pop_back();
	id[b[u].size()].insert(u);
}
void work() {
	ans.clear();
	for (int i=0;i<4;i++) {
		id[i].clear();
	}
	cin>>n>>m>>k;
	for (int i=1;i<=m;i++) {
		cin>>a[i];
	}
	for (int i=1;i<=n;i++) {
		b[i].clear();
		id[0].insert(i);
	}
	for (int i=1;i<=k;i++) {
		x[i]=y[i]=0;
	}
	if (n==1) {
		cout<<m<<"\n";
		for (int i=1;i<=m;i++) {
			cout<<"1 1\n";
		}
		return;
	}
	int cnt=0;
	for (int i=1;i<=m;i++) {
		int v=a[i];
		if (y[v]) {
			cnt--;
			if (y[v]==(int)b[x[v]].size()) {
				push(x[v],v);
			} else if (y[v]==1) {
				pop(x[v],v);
			} else {
				assert(false);
			}
		} else if (cnt<n*2-2) {
			cnt++;
			if (!id[1].empty()) {
				push(*id[1].begin(),v);
			} else if (!id[0].empty()) {
				push(*id[0].begin(),v);
			} else {
				assert(false);
			}
		} else {
			int u=-1;
			vector<int>tmp;
			for (int j=i+1;j<=m;j++) {
				if (y[a[j]]==2) {
					tmp.emplace_back(a[j]);
				} else {
					u=a[j];
					break;
				}
			}
			bool flag=0;
			for (int j:tmp) {
				flag|=x[j]==x[u];
			}
			if (flag) {
				push(*id[0].begin(),a[i]);
			} else {
				push(x[u],a[i]);
			}
		}
		/*
		for (int i=1;i<=k;i++) {
			cerr<<i<<":x="<<x[i]<<" y="<<y[i]<<endl;
		}
		for (int i=1;i<=n;i++) {
			cerr<<i<<":";
			for (int j:b[i]) {
				cerr<<j<<' ';
			}
			cerr<<endl;
		}
		for (int i=0;i<4;i++) {
			cerr<<i<<"|";
			for (int j:id[i]) {
				cerr<<j<<' ';
			}
			cerr<<endl;
		}
		cerr<<"========================\n";
		*/
	}
	cout<<ans.size()<<"\n";
	for (auto [opt,x,y]:ans) {
		if (opt==1) {
			cout<<opt<<' '<<x<<"\n";
		} else {
			cout<<opt<<' '<<x<<' '<<y<<"\n";
		}
	}
}

signed main() {
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	
	ios::sync_with_stdio(false),cin.tie(0);
	cout.precision(10),cout.setf(ios::fixed);
	
	int T;
	cin>>T;
	while (T--) {
		work();
	}
	
	return 0;
}
