#include<bits/stdc++.h>
using namespace std;
/*------------------------------fast io begin------------------------------*/
namespace Fread{
	const int SIZE=1<<16;
	char buf[SIZE],*S,*T;
	inline char getchar(){
		if(S==T){
			T=(S=buf)+fread(buf,1,SIZE,stdin);
			if(S==T)return '\n';
		}
		return *S++;
	}
}
namespace Fwrite{
	const int SIZE=1<<16;
	char buf[SIZE],*S=buf,*T=buf+SIZE;
	inline void flush(){
		fwrite(buf,1,S-buf,stdout);
		S=buf;
	}
	inline void putchar(char c){
		*S++=c;
		if(S==T)flush();
	}
	struct GreyCrane{
		~GreyCrane(){flush();}
	}HuiHe;
}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
template<typename T>inline void read(T&x){
	x=0;T f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-f;c=getchar();}
	while(isdigit(c))x=x*10+(c^48),c=getchar();
	x*=f;
}
inline void read(string&s){
	char c=getchar();s="";
	while(c==' '||c=='\n'||c=='\r')c=getchar();
	while(!(c==' '||c=='\n'||c=='\r'))s+=c,c=getchar();
}
template<typename T>inline void write(T x){
	if(x==0)putchar('0');
	else{
		if(x<0)putchar('-'),x=-x;
		static int sta[45];int top=0;
		while(x)sta[++top]=x%10,x/=10;
		while(top)putchar(sta[top--]+48);
	}
}
inline void write(char c){putchar(c);}
/*------------------------------fast io end------------------------------*/
#define all(x) x.begin(),x.end()
#define siz(x) ((int)x.size())
#define ll long long
#define pb push_back
#define fi first
#define se second
#define edl putchar('\n')
#define spc putchar(' ')
const int N=2e6+5,K=3e2+5;
int n,m,k,a[N],lst[K<<1],op[N];
inline void solve(){
	memset(op,0,sizeof(op));
	memset(lst,0,sizeof(lst));
	read(n),read(m),read(k);
	for(int i=1;i<=m;i++)read(a[i]);
	for(int i=1;i<=m;i++){
		if(!lst[a[i]]){
			lst[a[i]]=i;
		}else{
			for(int j=1;j<=k;j++){
				if(!lst[j])continue;
				if(lst[j]<lst[a[i]])lst[j]+=2;
				else lst[j]++;
			}
			if(i-lst[a[i]]==1){
				op[i]=op[i-1]=1;
			}
			if(i-lst[a[i]]==2){
				op[i]=op[i-2]=2;
				lst[a[i]]=0;
			}
		}
	}
	int now=0,cnt=0;
	for(int i=1;i<=m;i++){
		if(op[i]){
			if(op[i]==1){
				cout<<"1 "<<now+1<<endl;
				cout<<"1 "<<now+1<<endl;
				i++;
				continue;
			}else{
				cnt++;
				if(cnt==4)now^=1;
				cout<<"1 "<<(now^1)+1<<endl;
				cout<<"1 "<<now+1<<endl;
				cout<<"1 "<<(now^1)+1<<endl;
				i+=2;
				continue;
			}
		}else{
			cnt++;
			if(cnt==4)now^=1;
			cout<<"1 "<<now+1<<endl;
			if(cnt==6){
				cout<<"2 1 2"<<endl;
				cout<<"2 1 2"<<endl;
				cout<<"2 1 2"<<endl;
				cnt=0;
			}
		}
	}
}
int T;
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	read(T);
	while(T--)solve();
	return 0;
}
/*
1
2 16 3
1 1 2 1 3 1 2 2 3 1 3 1 1 3 2 1
*/
