#include<bits/stdc++.h>
using namespace std;
int n,m,K,a[2000010],pre[2000010],nxt[2000010],lst[2000010],x[2000010],y[2000010];
vector<pair<int,pair<int,int> > >res;
deque<int>Q[310];
inline void solve(){
	cin>>n>>m>>K;
	for(int i=1;i<=K;i++)lst[i]=0,x[i]=y[i]=0;
	for(int i=1;i<=m;i++)pre[i]=nxt[i]=0;
	for(int i=1;i<=m;i++){
		cin>>a[i];
		if(lst[a[i]])pre[i]=lst[a[i]],nxt[lst[a[i]]]=i,lst[a[i]]=0;
		else lst[a[i]]=i;
	}
	for(int i=1,j=1;i<=K;i+=4,j+=2){
		if(i<=K)x[i]=j,y[i]=j+1;
		if(i+1<=K)x[i+1]=j,y[i+1]=j+1;
		if(i+2<=K)x[i+2]=j,y[i+2]=j+1;
		if(i+3<=K)x[i+3]=j,y[i+3]=j+1;
	}
	res.clear();
	for(int i=1;i<=m;i++){
		int X=x[a[i]],Y=y[a[i]];
		if(pre[i]==0)res.push_back({1,{X,0}}),Q[X].push_back(a[i]);
		else{
			if(!Q[X].empty()&&Q[X].back()==a[i])res.push_back({1,{X,0}}),Q[X].pop_back();
			else Q[Y].push_back(a[i]),res.push_back({1,{Y,0}});
		}
	}
	for(int i=1;i<=n;i++){
		while(!Q[i].empty()){
			int u=Q[i].front();
			for(int j=i+1;j<=n;j++)
			if(!Q[j].empty()&&Q[j].front()==u){
				res.push_back({2,{i,j}});
				Q[i].pop_front(),Q[j].pop_front();
				break;
			}
		}
	}
	cout<<(int)res.size()<<'\n';
	for(auto i:res)
	if(i.first==1)cout<<i.first<<' '<<i.second.first<<'\n';
	else cout<<i.first<<' '<<i.second.first<<' '<<i.second.second<<'\n';
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	std::ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int T;cin>>T;
	while(T--)solve();
	return 0;
}