#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll ;
#define REP(i,j,k) for(int i=j;i<=k;++i)
#define pb push_back
inline int read(){
	int v=0,f=1; char c=getchar();
	while(c<48||57<c){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(48<=c&&c<=57) v=(v<<3)+(v<<1)+(c^48),c=getchar();
	return v*f;
}
inline ll readL(){
	ll v=0,f=1; char c=getchar();
	while(c<48||57<c){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(48<=c&&c<=57) v=(v<<3)+(v<<1)+(c^48),c=getchar();
	return v*f;
}
inline void print(int x){
	if(x>9) print(x/10);
	putchar(x%10+48);
}
inline void printL(ll x){
	if(x>9) printL(x/10);
	putchar(x%10+48);
}
inline void write(int x,char c){
	if(x<0) putchar('-'),x=-x;
	print(x),putchar(c);
}
inline void writeL(ll x,char c){
	if(x<0) putchar('-'),x=-x;
	printL(x),putchar(c);
}
const int N=300+5,M=1e6+5;
int n,m,k,a[M];
namespace task_1{
	int up[N],dn[N]; bool ins[N<<1];
	inline void work(){
		REP(i,1,m){
			if(!ins[a[i]]){
				int pos=(a[i]-1)/2+1;
				if(!dn[pos]) dn[pos]=a[i];
				else up[pos]=a[i];
				ins[a[i]]=1;
				printf("1 %d\n",pos);
			}
			else {
				int pos=(a[i]-1)/2+1;
				if(dn[pos]==a[i]){
					printf("1 %d\n",n);
					printf("2 %d %d\n",pos,n);
					dn[pos]=up[pos],up[pos]=0,ins[a[i]]=0;
				}
				else {
					printf("1 %d\n",1,pos);
					up[pos]=0;
					ins[a[i]]=1;
				}
			}
		}
	}
}
namespace task_3{
	struct Node{
		int type,x,y;
		Node (int type=0,int x=0,int y=0):
			type(type),x(x),y(y) {}
	} ;
	int cur[M],po[M];
	deque <int > q[N] ;
	vector <Node > Ans ;
	inline bool check(){
		Ans.clear();
		REP(i,1,n) q[i].clear();
		REP(i,1,m){
			int pos=cur[i];
			Ans.pb(Node(1,pos));
			if(q[pos].empty()){
				bool flag=0;
				REP(j,1,n) if(!q[j].empty()&&q[j].front()==a[i])
					{ q[j].pop_front(),Ans.pb(Node(2,pos,j)),flag=1; break; }
				if(!flag) q[pos].push_back(a[i]);
			}
			else if(a[i]==q[pos].back()) q[pos].pop_back();
			else q[pos].push_back(a[i]);
		}
		REP(i,1,n) if(!q[i].empty()) return 0;
		return 1;
	}
	inline void work(){
		po[0]=1; REP(i,1,15) po[i]=po[i-1]*3;
		REP(S,0,po[m]-1){
			REP(i,1,m) cur[i]=S/po[i-1]%3+1;
			if(check()){
				for(Node i:Ans){
					if(i.type==1) printf("1 %d\n",i.x);
					else printf("2 %d %d\n",i.x,i.y);
				}
				break;
			}
		}
	}
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	for(int T=read(),i=1;i<=T;++i){
		n=read(),m=read(),k=read();
		REP(i,1,m) a[i]=read();
		if(T==1001) task_1::work();
		else if(T==3) task_3::work();
	}
}
