#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=305;
const int M=2000005;
vector<int> s[N];
int L[N],R[N],a[M],n,m,k,ID[N];
void oper(int id,int v){
	if(L[id]<=R[id]&&v==s[id].back()){
		s[id].pop_back(),R[id]--;
	}else{
		s[id].push_back(v);
		R[id]++;
	}
	cout << 1 << ' ' << id << '\n';
}
void oper2(int id1,int id2){
	L[id1]++; L[id2]++;
	cout << 2 << ' ' << id1 << ' ' << id2 << '\n';
}
int bt[N],tp[N],ca[M*2],p1[M*2],p2[M*2],stk[4][M],id[M];
bool ok,used[M];
void check(){
	int oc=0;
	for(int i=1;i<=n;++i) bt[i]=0,tp[i]=-1;
	for(int i=1;i<=m;++i){
		if(used[i]){
			++oc;
			ca[oc]=1;
			p1[oc]=1;
			continue;
		}
		++oc;
		ca[oc]=1;
		p1[oc]=id[i];
		if(tp[i]>=bt[i]&&stk[id[i]][tp[id[i]]]==a[i]) --tp[id[i]];
		else{
			stk[id[i]][++tp[id[i]]]=a[i];
			if(tp[id[i]]-bt[id[i]]+1==1){
				for(int j=1;j<=n;++j){
					if(j==id[i]) continue;
					if(bt[j]<=tp[j]&&a[i]==stk[j][bt[j]]){
						++oc;
						ca[oc]=2;
						p1[oc]=id[i];
						p2[oc]=j;
						++bt[j];
						++bt[id[i]];
						break;
					}
				}
			}
		}
	}
	bool fi=1;
	for(int i=1;i<=n;++i)
		if(bt[i]<=tp[i]) fi=0;
	if(fi){
		cout << oc << '\n';
		for(int i=1;i<=oc;++i){
			if(ca[i]==1) cout << ca[i] << ' ' << p1[i] << '\n';
			else cout << ca[i] << ' ' << p1[i] << ' ' << p2[i] << '\n';
		}
		ok=1;
	}
}
int top,sstk[M];
void dfs(int step){
	if(ok) return ;
	if(step==top+1){
		check();
		return ;
	}
	for(int i=1;i<=n;++i){
		id[sstk[step]]=i;
		dfs(step+1);
	}
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int T; cin >> T;
	while(T--){
		cin >> n >> m >> k;
		for(int i=1;i<=m;++i) cin >> a[i];
		if(k==2*n-2){
			for(int i=1;i<=n;++i){
				s[i].clear();
				L[i]=0; R[i]=-1;
			}
			for(int i=1;i<=m;++i){
				int x=(a[i]+1)/2;
				if(L[x]>R[x]){oper(x,a[i]);continue;}
				if(s[x].back()==a[i]){oper(x,a[i]);continue;}
				if(s[x][L[x]]==a[i]){
					oper(n,a[i]);
					oper2(x,n);
					continue;
				}
				oper(x,a[i]);
			}
			continue;
		}
		top=0;
		for(int i=1;i<=m;++i){
			if(top&&a[sstk[top]]==a[i]){
				used[sstk[top]]=1;
				used[i]=1;
				--top;
			}else sstk[++top]=i;
		}
		ok=0;
		dfs(1);
	}
	return 0;
}
/*
2
3 10 5
1 2 3 4 5 2 3 4 5 1
3 10 5
1 2 3 4 5 2 3 4 5 1
*/