#include<bits/stdc++.h>
using namespace std;
const int N=2000005;
const int M=1005;
inline int read(){
	int t=1,x=0;
	char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') t=-1;
	for(;isdigit(ch);ch=getchar()) x=(x<<3)+(x<<1)+(ch^48);
	return t*x;
}
int t,ans;
int n,m,k,cnt;
int a[N];
int instk[M],stk[M],top,num[N];
int ou[M],cnt2,oul[M];
int stk2[M],stk3[M],top2,top3;
int id[M],dep[M];
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	t=read();
	while(t--){
		ans=0;
		memset(instk,0,sizeof(instk));
		memset(ou,0,sizeof(ou));
		memset(id,0,sizeof(id));
		memset(oul,0,sizeof(oul));
		memset(dep,0,sizeof(dep));
		for(int i=1;i<=top2;i++) stk2[i]=0;
		for(int i=1;i<=top3;i++) stk3[i]=0;
		for(int i=1;i<=top;i++) stk[i]=0;
		cnt=1,cnt2=0,top2=1,top3=1,top=0;
		n=read(),m=read(),k=read();
		if(n==2){
			for(int i=1;i<=m;i++){
				a[i]=read();
				if(!instk[a[i]]){
					instk[a[i]]=1;
					stk[++top]=a[i];
					ans++;
				}
				else{
					if(a[i]==stk[top]){
						ans++;
						instk[stk[top]]=0;
						top--;
						continue;
					}
					ans+=2;
				}
			}
			cout<<ans<<endl;
			for(int i=1;i<=m;i++){
				if(instk[a[i]]){
					if(ou[a[i]]) cout<<"1 2"<<endl<<"2 1 2"<<endl;
					else{
						puts("1 1");
						ou[a[i]]=1;
					}
				}
				else puts("1 1");
			}
		}
		else if(n==3){
			for(int i=1;i<=m;i++){
				a[i]=read();
				if(!instk[a[i]]){
					instk[a[i]]=1;
					stk[++top]=a[i];
					dep[a[i]]=top;
					ans++;
				}
				else{
					if(a[i]==stk[top]){
						ans++;
						instk[stk[top]]=0;
						top--;
						continue;
					}
					else{
						if(dep[a[i]]>dep[a[stk2[top2]]] || top2==1){
							ou[i]=2;
							id[a[i]]=2;
							stk2[++top2]=i;
						}
						else{
							stk3[++top3]=i;
							ou[i]=3;
							id[a[i]]=3;
						}
					}
					ans+=2;
				}
			}
			cout<<ans<<endl;
			int len=1;
			for(int i=1;i<=m;i++){
				if(instk[a[i]]){
					if(oul[a[i]]){
						cout<<"1 "<<ou[i]<<endl;
						if(stk[len]==a[i]){
							cout<<"2 1 "<<ou[i]<<endl;
							len++;
						}
					}
					else{
						puts("1 1");
						oul[a[i]]=1;
					}
				}
				else puts("1 1");
			}
			while(len<=top){
				cout<<"2 1 "<<id[stk[len]]<<endl;
				len++;
			}
		}
		else{
			for(int i=1;i<=m;i++){
				a[i]=read();
				if(!instk[a[i]]){
					instk[a[i]]=1;
					stk[++top]=a[i];
					ans++;
					ou[++cnt2]=1;
				}
				else{
					if(a[i]==stk[top]){
						top--;
						ans++;
						ou[++cnt2]=1;
						instk[stk[top]]=0;
						continue;
					}
					cnt++;
					if(cnt>n) cnt=2;
					num[a[i]]=cnt;
					ou[++cnt2]=cnt;
					ans++;
				}
			}
			ans+=top;
			cout<<ans<<endl;
			for(int i=1;i<=cnt2;i++) cout<<"1 "<<ou[i]<<endl;
			for(int i=1;i<=top;i++){
				cout<<"2 1 "<<num[stk[i]]<<endl;
			}
		}
	}
	fclose(stdin),fclose(stdout);
	return 0;
}
