#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 5;
int s[maxn],n,m,k,op,x,y,a[maxn],t[maxn],q[maxn],tot,z[5][maxn],pos[5],lim[5];
int bin[maxn],vis[maxn];
bool flag;
inline int read()
{
	int x = 0,f = 1;char ch = getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return f * x;
}
void input()
{
	n = read(),m = read(),k = read();
	for(int i = 1;i <= m;i++)
		a[i] = read();
}
void subtask1()
{
	int op = m;
	stack <int> s[305];
	for(int i = 1;i <= k;i++)
		t[i] = 0,bin[i] = 0;
	for(int i = 1;i <= m;i++)
		vis[i] = 0;
	for(int i = 1;i <= m;i++)
	{
		int d = (a[i] + 1) / 2;
		if(s[d].size()&&a[s[d].top()] == a[i])
			s[d].pop();		
		else
			s[d].push(i);
	}
	for(int d = 1;d <= n;d++)
	{
		tot = 0;
		while(s[d].size())
			q[++tot] = s[d].top(),s[d].pop();
		for(int j = 1;j + j <= tot;j++)
			swap(q[j],q[tot - j + 1]);
		for(int j = 3;j <= tot;j += 4)
			vis[q[j]] = 1,op++;
	}
	printf("%d\n",op);
	for(int i = 1;i <= m;i++)
	{
		int d = (a[i] + 1) / 2;
		if(!vis[i])
			printf("1 %d\n",d);
		else
			printf("1 %d\n2 %d %d\n",n,d,n);
	}
}
void output(int op)
{
	printf("%d\n",op + m);
	for(int i = 1;i <= n;i++)
		pos[i] = 0,lim[i] = 0;
	for(int i = 1;i <= m;i++)
	{
		z[s[i]][++lim[s[i]]] = a[i];
		if(lim[s[i]] >= 2&&z[s[i]][lim[s[i]]] == z[s[i]][lim[s[i]] - 1])
			lim[s[i]] -= 2;
	}
	for(int i = 1;i <= m;i++)
		printf("1 %d\n",s[i]);
	int nu = 0;
	for(int i = 1;i <= n;i++)
		nu += lim[i];
	while(nu)
	{
		for(int i = 1;i <= n;i++)
			for(int j = i + 1;j <= n;j++)
				if(lim[i] - pos[i]&&lim[j] - pos[j]&&z[i][pos[i] + 1] == z[j][pos[j] + 1])
					pos[i]++,pos[j]++,nu -= 2,printf("2 %d %d\n",i,j);
	}
	flag = 1;
}
void check()
{
	for(int i = 1;i <= n;i++)
		pos[i] = 0,lim[i] = 0;
	for(int i = 1;i <= m;i++)
	{
		z[s[i]][++lim[s[i]]] = a[i];
		if(lim[s[i]] >= 2&&z[s[i]][lim[s[i]]] == z[s[i]][lim[s[i]] - 1])
			lim[s[i]] -= 2;
	}
	int nu = 0;
	for(int i = 1;i <= n;i++)
		nu += lim[i];
	int op = nu / 2;
	while(nu)
	{
		bool flag = 0;
		for(int i = 1;i <= n;i++)
			for(int j = i + 1;j <= n;j++)
				if(lim[i] - pos[i]&&lim[j] - pos[j]&&z[i][pos[i] + 1] == z[j][pos[j] + 1])
					pos[i]++,pos[j]++,nu -= 2,flag = 1;
		if(!flag)
			return ;
	}
	output(op);
}
void dfs(int k)
{
	if(flag)
		return ;
	if(k == m + 1)
	{
		check();
		return ;
	}
	for(int i = 1;i <= n;i++)
		s[k] = i,dfs(k + 1);
}
void subtask2()
{
	dfs(1);
}
int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T = read();
	while(T--)
	{
		flag = 0;
	//	clear();
		input();
		if(n <= 3&&m <= 14)
			subtask2();
		else
			subtask1();		
	}
	return 0 ;
}
/*
NOIP 2022 RP++
*/

