#include <bits/stdc++.h>
using namespace std;
const int N=1005;
int n,m,k,vis[N],a[2000005],sta[2000005],FL[2000005],In[2000005];
int val[N][2],top[N];
int main() {
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T; scanf("%d",&T);
	while (T--) {
		scanf("%d%d%d",&n,&m,&k);
		int tot=0;
		for (int i=1; i<=k; i++) vis[i]=0;
		for (int i=1; i<=m; i++) {
			scanf("%d",&a[i]);
			if (!vis[a[i]]) vis[a[i]]=(++tot);
			a[i]=vis[a[i]];
		}
		for (int i=1; i<=m; i++) In[i]=FL[i]=0;
		if (n==2) {
			int top=0;
			for (int i=1; i<=m; i++) {
				if (!top) sta[++top]=i;
				else if (a[sta[top]]==a[i]) In[sta[top]]=In[i]=1,top--;
				else if (a[sta[top-1]]==a[i]) In[sta[top-1]]=In[i]=-sta[top],sta[top-1]=sta[top],top--;
				else sta[++top]=i;
			}
			int num=m;
			for (int i=1; i<=top; i++) {
				if (i%6>=1 && i%6<=3) In[sta[i]]=1;
				else In[sta[i]]=2;
				if (i%6==0) FL[sta[i]]=1,num++;
			}
			printf("%d\n",num); sta[top+1]=m+1;
			for (int j=1; j<=top; j++) {
				for (int i=sta[j]; i>=sta[j-1]+1; i--) 
					if (In[i]<0) In[i]=3-In[-In[i]];
				for (int i=sta[j]; i<=sta[j+1]-1; i++)
					if (In[i]<0) In[i]=3-In[-In[i]];
			}
			for (int i=1; i<=m; i++) {
				printf("1 %d\n",In[i]);
				if (FL[i]) printf("2 1 2\n");
			}
		} else {
			for (int i=1; i<=k; i++) val[i][0]=val[i][1]=top[i]=0;
			int num=m;
			for (int i=1; i<=m; i++) {
				int id=(a[i]+1)/2;
				if (top[id] && val[id][top[id]]==a[i]) top[id]--,In[i]=id;
				else {
					if (top[id]<=1) val[id][++top[id]]=a[i],In[i]=id;
					else if (top[id]==2) {
						In[i]=n; FL[i]=1; num++;
						val[id][1]=val[id][2],top[id]--;
					}
				}
			}
			printf("%d\n",num);
			for (int i=1; i<=m; i++) {
				printf("1 %d\n",In[i]);
				if (FL[i]) printf("2 %d %d\n",(a[i]+1)/2,n);
			}
		}
	}
}
