#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,k;
int a[N],p[N],b[N];
struct node{
	int op,s,s1,s2;
};
void ____(){
	cin>>n>>m>>k;
	for(int i=1;i<=m;i++) cin>>a[i];
	for(int i=1;i<=k;i++) p[i]=i;
	do{
//		cout<<"YES\n";
		int res=0;
		deque<int>sta[305];
		vector<node>g;
		for(int i=1;i<=k;i++) b[p[i]]=(i-1)%n+1;
		for(int i=1;i<=m;i++){
			int pos=b[a[i]];
			if(sta[pos].empty()){
				g.push_back({1,pos,0,0});
				sta[pos].push_back(a[i]),res++;
			}
			else{
				if(sta[pos].back()==a[i]){
					g.push_back({1,pos,0,0});
					sta[pos].pop_back();
					res--;
				}
				else if(sta[pos].front()==a[i]){
					if(sta[n].empty()) g.push_back({1,n,0,0}),g.push_back({2,0,n,pos});
					else if(sta[n-1].empty()) g.push_back({1,n-1,0,0}),g.push_back({2,0,n-1,pos});
					sta[pos].pop_front();
					res--;
				}
				else{
					g.push_back({1,pos,0,0});
					sta[pos].push_back(a[i]),res++;
				}
			}
//			cout<<res<<"\n";
		}
//		for(int i=1;i<=k;i++) cout<<p[i]<<" ";
//		cout<<"\n";
//		for(int i=1;i<=k;i++) cout<<b[i]<<" ";
//		cout<<"\n";
		if(res==0){
			cout<<g.size()<<"\n";
			for(auto it:g){
				cout<<it.op<<" ";
				if(it.op==1) cout<<it.s<<"\n";
				else cout<<it.s1<<" "<<it.s2<<"\n";
			}
			return ;
		}
	}while(next_permutation(p+1,p+k+1));
	return ;
}
signed main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int T=1;
	cin>>T;
	while(T--) ____();
}



