#include<bits/stdc++.h>
#define maxn 2000005
using namespace std;
int n,T,k,m,a[maxn],id[maxn],x,f[maxn];
inline int read(){
	int ret=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-f;ch=getchar();}
	while (ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=getchar();
	return ret*f;
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	while (T--){
		m=read(),n=read(),k=read();
		if (k==2*m-2){
			for (int i=1;i<=n;i++){
				a[i]=read();
				if (a[i]<m) x=a[i]+m-1;
				else x=a[i]-m+1;
				if (!id[a[i]]&&!id[x]){
					printf("1 %d\n",min(x,a[i]));
					f[a[i]]=1,id[a[i]]=1;
					continue;
				}
				if (!id[a[i]]&&id[x]){
					id[a[i]]=1;
					printf("1 %d\n",min(x,a[i]));
					continue;
				}
				if (id[a[i]]&&!id[x]){
					printf("1 %d\n",min(x,a[i]));
					f[a[i]]=0,id[a[i]]=0;
					continue;
				}
				if (id[a[i]]&&id[x]){
					id[a[i]]=0;
					if (!f[a[i]]) printf("1 %d\n",min(x,a[i]));
					else f[x]=1,f[a[i]]=0,printf("1 %d\n2 %d %d\n",m,min(x,a[i]),m);
					continue;
				}
			}
			return 0;
		}
	}
}