#include<bits/stdc++.h>
#define M 2000010
#define N 310
using namespace std;
typedef long long ll;
inline ll rl(){
	ll ans=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9')ans=ans*10+c-'0',c=getchar();
	return ans*f;
}
ll T,n,m,k,a[N];
deque<ll>s[N];
ll v[N<<1];
ll ans[M<<1][3],sum;
void work(){//k=2n-2
	memset(v,0,sizeof(v));
	ll u;
	for(ll i=1;i<=m;i++){
		if(v[a[i]]){
			u=v[a[i]];
			if(s[u].back()==a[i]){
				sum++;
				ans[sum][0]=1,ans[sum][1]=u;
				
				s[u].pop_back();
			}else{
				sum++;
				ans[sum][0]=1,ans[sum][1]=n;
				sum++;
				ans[sum][0]=2,ans[sum][1]=u,ans[sum][2]=n;
				
				s[u].pop_front();
			}
			v[a[i]]=0;
		}else{
			for(ll j=1;j<n;j++){
				if(s[j].size()<2){
					sum++;
					ans[sum][0]=1,ans[sum][1]=j;
					
					s[j].push_back(a[i]);
					v[a[i]]=j;
					break;
				}
			}
		}
	}
}
void srch(){
	ll x=1,y=2;
	for(ll i=1;i<=m;i++){
		if(s[x].empty()&&!s[y].empty()){
			swap(s[x],s[y]);
			swap(x,y);
		}
		if(s[x].empty()){
			s[x].push_back(a[i]);
			sum++;
			ans[sum][0]=1,ans[sum][1]=x;
		}else{
			if(s[x].back()==a[i]){
				s[x].pop_back();
				sum++;
				ans[sum][0]=1,ans[sum][1]=x;
			}else if(s[x].front()==a[i]){
				sum++;
				ans[sum][0]=1,ans[sum][1]=y;
				sum++;
				ans[sum][0]=2,ans[sum][1]=x,ans[sum][2]=y;
				s[x].pop_front();
			}else if(s[x].size()<2){
				sum++;
				ans[sum][0]=1,ans[sum][1]=x;
				s[x].push_back(a[i]);
			}else{
				sum++;
				if(a[i+1]==s[x].front()){
					s[x].push_back(a[i]);
					ans[sum][0]=1,ans[sum][1]=x;
				}else{
					s[y].push_back(a[i]);
					ans[sum][0]=1,ans[sum][1]=y;
				}
			}
		}
	}
}
bool ok;
void dfs(ll x){
	printf("%lld\n",x);
	if(ok)return;
	if(x>m){
		ok=s[1].empty()&&s[2].empty()&&s[3].empty();
		return;
	}
	for(ll i=1;i<=3;i++){
		if(s[i].empty())continue;
		if(s[i].back()==a[x]){
			sum++;
			ans[sum][0]=1,ans[sum][1]=i;
			s[1].pop_back();
			dfs(x+1);
			sum--;
			s[1].push_back(a[x]);
			return;
		}
	}
	for(ll i=1;i<=3;i++){
		if(s[i].empty())continue;
		if(a[x]!=s[i].front())continue;
		for(ll j=1;j<=3;j++){
			if(!s[j].empty())continue;
			sum++;
			ans[sum][0]=1,ans[sum][1]=j;
			sum++;
			ans[sum][0]=2,ans[sum][1]=i,ans[sum][2]=j;
			
			s[i].pop_front();
			dfs(x+1);
			sum-=2;
			s[i].push_front(a[x]);
			return;
		}
	}
	sum++;
	
	ans[sum][0]=1;
	ans[sum][1]=1;
	s[1].push_back(a[x]);
	dfs(x+1);
	s[1].pop_back();
	
	ans[sum][1]=2;
	s[2].push_back(a[x]);
	dfs(x+1);
	s[2].pop_back();
	
	ans[sum][1]=3;
	s[3].push_back(a[x]);
	dfs(x+1);
	s[3].pop_back();
	
	sum--;
}
void fight(){
	ll x=1,y=2,z=3;
}
signed main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=rl();
	while(T--){
		n=rl(),m=rl(),k=rl();
		for(ll i=1;i<=m;i++)a[i]=rl();
		if(n==1){
			printf("%lld\n",m);
			for(ll i=1;i<=m;i++)printf("1 1\n");
			continue;
		}
		for(ll i=1;i<=n;i++)s[i].clear();
		sum=ok=0;
		if(k==2*n-2)work();
		else if(n==2)srch();
		else if(m<=14)dfs(1);
		else fight();
		printf("%lld\n",sum);
		for(ll i=1;i<=sum;i++){
			if(ans[i][0]==1)printf("1 %lld\n",ans[i][1]);
			else printf("2 %lld %lld\n",ans[i][1],ans[i][2]);
		}
	}
	return 0;
}
