#include<bits/stdc++.h>
using namespace std;
int TT,n,m,k,x;
int T[305],W[305],Q[305][10005];
int sum[305],top[305],a[1000006];
int topp,topq,p[105],q[105],tp,tq;
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	srand(time(0));
	scanf("%d",&TT);
		while(TT--){
		scanf("%d%d%d",&n,&m,&k);
		if(k==2*n-2){
			for(int i=1;i<=n;i++){
				sum[i]=top[i]=0;
			}
			for(int i=1;i<=m;i++){
				scanf("%d",&x);
				int num=(x+1)/2;
			//	printf("!%d\n",num);
				if(sum[num]==0){
					printf("1 %d\n",num);
					sum[num]++;
					top[num]=x;
				}else{
					if(top[num]==x){
						printf("1 %d\n",num);
						sum[num]--;
						top[num]=0;
						if(sum[num]!=0){
							if(x%2==0) top[num]=x-1;
							else top[num]=x+1;
						}
					}else{
						if(sum[num]==2){
							printf("1 %d\n",n);
							printf("2 %d %d\n",num,n);
							sum[num]--;
						}else{
							printf("1 %d\n",num);
							sum[num]++;
							top[num]=x;
						}
					}
				}
			}
		}else{
			if(n==2){
				for(int i=1;i<=m;i++){
					scanf("%d",&a[i]);
				}
				topq=-1;
				topp=-1;
				tq=0;
				tp=0;
				// q topq p topp
				for(int i=1;i<=m;i++){
					if(topq!=tq-1&&q[topq]==a[i]){
						printf("1 1\n");
						topq--;
					}else{
						if(topp!=tp-1&&p[topp]==a[i]){
							printf("1 2\n");
							topp--;
						}else{
						//	if()
							if(a[i+1]==a[i]){
								printf("1 1\n");
								topq++;
								q[topq]=a[i];
							}else{
								if(topp!=tp-1&&topq!=tq-1){
									if(a[i+1]==q[topq]){
										printf("1 2\n");
										topp++;
										p[topp]=a[i];
									}else{
										printf("1 1\n");
										topq++;
										q[topq]=a[i];
									}
								}else{
									if(topq!=tq-1){
										if(q[tq]==a[i]){
											printf("1 2\n2 1 2\n");
											tq++;
										}else{
											if(a[i+1]==q[tq]){
												printf("1 1\n");
												topq++;
												q[topq]=a[i];
											}else{
												printf("1 2\n");
												topp++;
												p[topp]=a[i];
											}
										}
									}else{
										if(p[tp]==a[i]){
											printf("1 1\n2 1 2\n");
											tp++;
										}else{
											if(a[i+1]==p[tp]){
												printf("1 2\n");
												topp++;
												p[topp]=a[i];
											}else{
												printf("1 1\n");
												topq++;
												q[topq]=a[i];
											}
										}
									}
								}
							}
							
						}
					}
				}
			}else{
				for(int i=1;i<=n;i++) T[i]=-1,W[i]=0;
				for(int i=1;i<=m;i++){
					scanf("%d",&x);
					bool pd=false;
					for(int i=1;i<n;i++){
						if(T[i]<W[i]) continue;
						if(Q[i][T[i]]==x){
							printf("1 %d\n",i);
							T[i]--;
							pd=true;
							break;
						}
						if(Q[i][W[i]]==x){
							printf("1 %d\n2 %d %d\n",n,i,n);
							W[i]++;
							pd=true;
							break;
						}
					}
					if(pd) continue;
					for(int i=1;i<n;i++){
						if(T[i]<=W[i]){
							printf("1 %d\n",i);
							T[i]++;
							Q[i][T[i]]=x;
							pd=true;
							break;
						}
					}
					if(pd) continue;
					int wh=rand()%(n-1)+1;
					printf("1 %d\n",wh);
					T[wh]++;
					Q[wh][T[wh]]=x;
				}
			}
		}
	}
	return 0;
}