#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=1;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}

int const N=300+3;
int const M=2e6+3;
int T,n,m,k,x,top,pla,plaa,cnt,num,a[M],sta[2*N],pos[2*N],vis[2*N];
int ans[4000003][3],pos0[M],step[M];

int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	int flag=0;
	while (T--){
		n=read();m=read();k=read();
		top=cnt=num=0;
		for (int i=2*n;i>=2;i-=2) pos0[++top]=i;
		for (int i=2*n-1;i>=1;i-=2) pos0[++top]=i;
		for (int i=1;i<=2*n;i++) sta[i]=0;
		for (int i=1;i<=k;i++) pos[i]=0;
		for (int i=1;i<=m;i++){
			a[i]=read();
			if (pos[a[i]]==1){
				pos[a[i]]=0;
				step[++cnt]=a[i];
			}
			else pos[a[i]]=1;
		}
		step[0]=1;
		for (int i=1;i<=m;i++){
			x=a[i];
			if (pos[x]==0){
				int Flag=0;flag=1;
				if (x==step[step[0]] && step[0]<=cnt){
					Flag=1;
					for (int j=2;j<=2*n;j++){
						if (sta[j]==0 && sta[j-1]!=0 && vis[sta[j-1]]==0){
							flag=0;
							sta[j]=x;
							pos[x]=j;
							num++;
							ans[num][0]=1;
							ans[num][1]=j;
							break;
						}
					}
				}
				if (flag==0){
					if (Flag==1) vis[x]=1,step[0]++;
					continue;
				}
				while (sta[pos0[top]]!=0) top--;
				pla=-1;
				for (int j=top;j>=1;j--) if (sta[pos0[j]]==0 && (pos0[j]%2==1 || vis[sta[pos0[j]-1]]==0)){
					pla=pos0[j];
					break;
				}
				if (pla==-1){
					for (int j=1;j<=top;j++) if (sta[pos0[j]]==0){
						pla=pos0[j];
						break;
					}
				}
				if (Flag==1) vis[x]=1,step[0]++;
				pos[x]=pla;
				sta[pla]=x;
				num++;
				ans[num][0]=1;
				ans[num][1]=pla;
			}
			else{
				pla=pos[x];
				if (vis[sta[pla]]==1) vis[sta[pla]]=0;
				pos[x]=0;sta[pla]=0;
				if (pla&1 && sta[pla+1]){
					while (sta[pos0[top]]!=0 & top>0) top--;
					for (int j=top;j>=1;j--) if (sta[pos0[j]]==0 && pos0[j]%2==0){	
						plaa=pos0[top];
						break;
					}
					pos[sta[pla+1]]=pla;
					sta[pla]=sta[pla+1];
					sta[pla+1]=0;
					pos0[++top]=pla+1;
					num++;
					ans[num][0]=1;
					ans[num][1]=plaa;
					num++;
					ans[num][0]=2;
					ans[num][1]=pla;
					ans[num][2]=plaa;
				}
				else{
					pos0[++top]=pla;
					num++;
					ans[num][0]=1;
					ans[num][1]=pla;
				}
			}
		}
		cout<<num<<endl;
		for (int i=1;i<=num;i++){
			cout<<ans[i][0];
			putchar(' ');
			for (int j=1;j<=ans[i][0];j++){
				cout<<(ans[i][j]+1)/2;
				putchar(' ');
			}
			putchar('\n');
		}
	}
	return 0;
}