#include<bits/stdc++.h>
using namespace std;
const int mx=3e4+2;
const int mt=6e2+6;
int n,m,T,k;
int a[mx],tong[mt],anst[mt];
int main() {
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	scanf("%d",&T);
	for(int i=1; i<=T; i++) {
		scanf("%d%d%d",&n,&m,&k);
		for(int j=1; j<=m; j++) {
			scanf("%d",a+j);
		}
		if(T%10==1) {
			for(int j=1; j<=m; j++) {
				bool bok=false;
				int vis=0;
				int tailvis=0;
				for(int k=1; k<n; k++) {
					if(tong[k]==0) {
						vis=k;
					}
					if(tong[k]==a[j]) {
						if(tong[k+n]==0) {
							tong[k]=0;
							bok=true;
							printf("1 %d\n",k);
							break;
						}
						if(tong[k+n]!=0) {
							bok=true;
							printf("1 %d\n",n);
							printf("2 %d %d\n",n,k);
							tong[k]=tong[k+n];
							tong[k+n]=0;
							break;
						}
					}
				}
				if(!bok) {
					for(int k=n+1; k<2*n; k++) {
						if(tong[k]==0) {
							tailvis=k;
						}
						if(tong[k]==a[j]) {
							bok=true;
							tong[k]=0;
							printf("1 %d\n",k-n);
							break;
						}
					}
				}
				if(!bok) {
					if(vis!=0) {
						tong[vis]=a[j];
						printf("1 %d\n",vis);
					} else {
						tong[tailvis]=a[j];
						printf("1 %d\n",tailvis-n);
					}
				}
			}
		}
		if(T%10==2) {
			for(int j=1; j<=m; j++) {
				if(tong[1]!=0&&tong[2]!=0) {
					if(tong[1]==a[j]&&tong[3]==0) {
						tong[1]=0;
						printf("1 1\n");
						continue;
					}
					if(tong[2]==a[j]&&tong[4]==0) {
						tong[2]==0;
						printf("1 2\n");
						continue;
					}
					if(a[j]!=tong[1]&&a[j]!=tong[2]) {
						if(a[j+1]==tong[1]) {
							tong[3]=a[j];
							printf("1 2\n");
							continue;
						} else {
							tong[4]=a[j];
							printf("1 3\n");
							continue;
						}
					}
				}
				if(tong[1]==0) {
					if(tong[2]==a[j]&&tong[4]!=0) {
						tong[2]=tong[4];
						tong[4]=0;
						printf("1 1\n");
						printf("2 1 2\n");
						continue;
					}
					tong[1]=a[j];
					printf("1 1\n");
					continue;
				}
				if(tong[2]==0) {
					if(tong[1]==a[j]&&tong[3]!=0) {
						tong[1]=tong[3];
						tong[3]=0;
						printf("1 2\n");
						printf("2 1 2\n");
						continue;
					}
					tong[2]=a[j];
					printf("1 2\n");
					continue;
				}
			}
		}
	}
	return 0;
}
