#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;
const int N=333;
const int M=2*1e6+10;

int n,m,k,T,c,sz,g,cnt,flag;
int h[N],a[N],tab[M<<2][3];

vector<int> v[N];

int read(){
	int x=0,c=getchar();
	while (c<'0' || c>'9') c=getchar();
	while (c>='0' && c<='9') x=x*10+c-48,c=getchar();
	return x;
}

void allclear(){
	n=m=k=0;cnt=0;
	for (int i=1;i<=n;i++)
		while (v[i].size()) v[i].pop_back();
	memset(h,0,sizeof(h));
	memset(tab,0,sizeof(tab));
}

void dfs(int t){
	if (flag) return;
	if (t>m){
		bool succ=1;
		for (int i=1;i<=n;i++)
			if (h[i]<v[i].size()) succ=0;
		if (succ){
			printf("%d\n",cnt);
			for (int i=1;i<=cnt;i++){
				for (int j=0;j<=tab[i][0];j++)
					printf("%d ",tab[i][j]);
				puts("");
			}
			flag=1;
		}
		return;
	}
	printf("%d\n",cnt);
	for (int i=1;i<=cnt;i++){
		for (int j=0;j<=tab[i][0];j++)
			printf("%d ",tab[i][j]);
		puts("");
	}
	puts("######################");
	for (int i=1;i<=n;i++){
		int tmp=0,tmpp=0,pushed=0,sz=v[i].size();
		if (h[i]>=sz){
			cnt++;tab[cnt][0]=1;tab[cnt][1]=i;
			v[i].push_back(a[t]);
			dfs(t+1);
			v[i].pop_back();
		}
		else{
			if (h[i]<sz){
				cnt++;tab[cnt][0]=1;tab[cnt][1]=i;
				if (v[i][sz-1]==a[t]){
					tmp=v[i][sz-1];
					v[i].pop_back();
				}else{
					v[i].push_back(a[t]);
					pushed=1;
				}
			}
			for (int j=1;j<=n;j++){
				if (j==i) continue;
				if (h[i]<v[i].size() && h[j]<v[j].size() && v[i][h[i]]==v[j][h[j]]){
					cnt++;tab[cnt][0]=2;tab[cnt][1]=i;tab[cnt][2]=j;
					h[i]++;h[j]++;
					tmpp=j;
				}
			}
			dfs(t+1);
			if (tmp) v[i].push_back(tmp),cnt--;
			if (tmpp) h[i]--,h[tmpp]--,cnt--;
			if (pushed) v[i].pop_back(),cnt--;
		}
	}
}

int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	if (T%10==1){
		while (T--){
			allclear();
			n=read();m=read();k=read();
			for (int i=1;i<=m;i++){
				c=read();
				g=(c+1)/2;sz=v[g].size();
				if (h[g]>=sz){
					v[g].push_back(c);cnt++;
					tab[cnt][0]=1;
					tab[cnt][1]=g;
					continue;
				}
				if (v[g][sz-1]==c){
					v[g].pop_back();cnt++;
					tab[cnt][0]=1;
					tab[cnt][1]=g;
				}else{
					if (v[g][h[g]]==c){
						h[g]++;cnt++;
						tab[cnt][0]=1;
						tab[cnt][1]=n;
						cnt++;
						tab[cnt][0]=2;
						tab[cnt][1]=g;
						tab[cnt][2]=n;
					}else{
						v[g].push_back(c);cnt++;
						tab[cnt][0]=1;
						tab[cnt][1]=g;
					}
				}
			}
			printf("%d\n",cnt);
			for (int i=1;i<=cnt;i++){
				for (int j=0;j<=tab[i][0];j++)
					printf("%d ",tab[i][j]);
				puts("");
			}
		}
		return 0;
	}
	T=read();
	while (T--){
		allclear();
		n=read();m=read();k=read();
		for (int i=1;i<=m;i++) a[i]=read();
		flag=0;dfs(1);
	}
	return 0;
}
