#include<bits/stdc++.h>
using namespace std;
const int N=305;
const int M=2e6+10;
int T,n,m,k,a[M];
int st[N][50005];
int s[5][2000010];
int r[N];
int ans[M][3],cnt;
bool flag;
inline int read(){
	char c=getchar(); int d=0,e=1;
	while (c<'0'||c>'9') {
		if (c=='-') e=-1;
		c=getchar();
	}
	while (c>='0'&&c<='9') {
		d=(d<<3)+(d<<1)+c-'0';
		c=getchar();
	}
	return d*e;
}
inline void solve1(){
	for (int i=1;i<=n;++i){
		int si=(a[i]+1)/2;
		if (st[si][1]==a[i]){
			printf("1 %d\n",n);
			printf("2 %d %d\n",si,n);
			st[si][1]=st[si][r[si]];
			r[si]--;
		}else
		{
			printf("1 %d\n",si);
			st[si][++r[si]]=a[i];
			while (r[si]>1&&st[si][r[si]]==st[si][r[si]-1])
				r[si]-=2;
		}
	}
}
inline void check(){
	bool f=true;
	if (cnt>2*m) f=false;
	if (!f) return;
	for (int i=1;i<n;++i) 
		if (r[i]) f=false;
	if (f) flag=true;
}
inline void dfs(int x){
	if (x>m) {check(); return;}
	if (flag) return;
	for (int i=1;i<=n;++i){
		if (flag) return;
		ans[++cnt][1]=1; ans[cnt][2]=i;
		s[i][++r[i]]=a[i];
		int co=0;
		int lst;
		if (s[i][r[i]]==s[i][r[i]-1]) lst=s[i][r[i]],r[i]-=2,co=1;
		dfs(x+1);
		cnt--;
		if (!co) r[i]--;else 
		if (co==1) s[i][++r[i]]=lst;
	}
}
inline void solve3(){
	dfs(1);
	for (int i=1;i<=cnt;++i){
		printf("%d",ans[i][1]);
		for (int j=1;j<=ans[i][1];++j)
			printf(" %d",ans[i][j]);
		printf("\n");
	}
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	while (T--){
		n=read(); m=read(); k=read();
		for (int i=1;i<=n;++i) r[i]=0;
		for (int i=1;i<=m;++i) a[i]=read();
		if (k==2*n-2) solve1();
		else if (n==3) solve3();
		//if (k!=2*n-2&&n!=3) solve2();
	}
	return 0;
}
