//妹子when???
#include<bits/stdc++.h>
#define pb push_back
#define pc putchar
#define fi first
#define se second
#define eb emplace_back
#define lc (x<<1)
#define rc (x<<1|1)
#define mid ((l+r)>>1)
#define mp make_pair
#define mt make_tuple
using namespace std;
template<class T>void read(T&x){
	char c=getchar();bool f=0;x=0;
	for(;!isdigit(c);c=getchar())if(c=='-')f=1;
	for(;isdigit(c);c=getchar())x=x*10+c-'0';
	if(f)x=-x;
}
template<class T,class ...Arg>void read(T&x,Arg&...arg){read(x);read(arg...);}
template<class T>void write(T x){
	if(x<0)x=-x,pc('-');
	if(x>=10)write(x/10);
	pc(x%10+'0');
}
template<class T,class ...Arg>void write(T x,Arg ...arg){write(x);pc(' ');write(arg...);}
template<class ...Arg>void writeln(Arg ...arg){write(arg...);pc('\n');}
const int N=2e6+100;
int T,n,m,k,a[N];
deque<int>st[400];
vector<tuple<int,int,int>>res;
int stk[N],top,fa[N],vis[N],ans[N];bool flag;
int get(int x){
	if(vis[x]!=-1)return vis[x];
	return vis[x]=(get(fa[x])^1);
}
void dfs(int now){
	if(now==m+1){
		if(!st[1].size()&&!st[2].size()&&!st[3].size())flag=1;
		return;
	}
	for(int i=1;i<=n;i++){
		res.eb(1,i,0);
		if(st[i].size()&&st[i].back()==a[now]){
			st[i].pop_back();
			dfs(now+1);if(flag)return;
			st[i].pb(a[now]);
		}else{
			st[i].push_back(a[now]);
			dfs(now+1);if(flag)return;
			st[i].pop_back();
		}
		res.pop_back();
	}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(st[i].size()&&st[j].size()&&st[i].front()==st[j].front()){
				res.eb(2,i,j);
				int _=st[i].front();
				st[i].pop_front();st[j].pop_front();
				dfs(now+1);if(flag)return;
				st[i].push_front(_);st[j].push_front(_);
				res.pop_back();
			}
}
signed main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	read(T);
	while(T--){
		read(n,m,k);res.clear();
		for(int i=1;i<=m;i++)read(a[i]);
		if(n==1){
			writeln(m);
			for(int i=1;i<=m;i++)writeln(1,1);
		}else{
			for(int i=1;i<=n;i++)st[i].clear();
			if(k==2*n-2){
				for(int i=1;i<=m;i++){
					int bel=(a[i]+1)/2;
					if(st[bel].size()&&st[bel].back()==a[i])st[bel].pop_back(),res.eb(1,bel,0);
					else if(st[bel].size()&&st[bel].front()==a[i])st[bel].pop_front(),res.eb(1,n,0),res.eb(2,bel,n);
					else st[bel].push_back(a[i]),res.eb(1,bel,0);
				}
			}else if(n==2&&k==3){
				for(int i=1;i<=m;i++)vis[i]=-1,fa[i]=0;
				top=0;
				for(int i=1;i<=m;i++){
					if(top&&a[stk[top]]==a[i]){
						vis[stk[top]]=vis[i]=0;
						top--;
					}else if(top>1&&a[stk[top-1]]==a[i]){
						fa[stk[top-1]]=fa[i]=stk[top];
						top--;stk[top]=stk[top+1];
					}else stk[++top]=i;
				}
				for(int i=1;i<=top;i++)vis[stk[i]]=i<=top/2;
				for(int i=1;i<=m;i++)vis[i]=get(i),res.eb(1,vis[i]+1,0);
				for(int i=1;i<=top/2;i++)res.eb(2,1,2);
			}else if(n==3){
				flag=0;dfs(1);
			}
			writeln(res.size());
			for(auto wyh:res){
				int a,b,c;tie(a,b,c)=wyh;
				if(a==1)writeln(a,b);
				else writeln(a,b,c);
			}
		}
	}
	return 0;
}
