#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=610,M=2000010;

int n,m,k,x;
vector <int> a[N];
stack <int> v[N];
int b[N],c[M],vv[N];
bool bo,bo2[N];
int bo1[N];
vector <pair<int,int> > pa;

void clear(int t)
{
	bool bo=0;
	while (vv[t])
	{
		bo=0;
		x=v[t].top();
		for (int i=1;i<=n;i++)
		{
			if (i==t) continue;
			if (vv[i]&&v[i].top()==x)
			{
				bo=1;
//				cout<<max(i,t)<<"   "<<min(i,t)<<endl;
				pa.push_back({max(i,t),min(i,t)});
				vv[i]--;
				vv[t]--;
				v[i].pop();
				v[t].pop();
				break;
			}
		}
		if (!bo) return;
	}
}

int main()
{
	int T;
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d%d%d",&n,&m,&k);
		for (int i=1;i<=n;i++)
		{
			bo1[i]=0;
		}
		for (int i=1;i<=m;i++)
		{
			scanf("%d",&c[i]);
			a[c[i]].push_back(i);
		}
		for (int i=1;i<=k;i++)
		{
			b[i]=bo2[i]=0;
		}
		for (int i=1;i<=m;i++)
		{
//			cout<<i<<endl;
			b[c[i]]++;
			if (b[c[i]]%2==1)
			{
				bo=0;
				for (int j=1;j<=n;j++)
				{
					if (bo1[j]==2) continue;
					if (vv[j])
					{
						x=v[j].top();
						if (a[x][b[x]]>a[c[i]][b[c[i]]])
						{
							bo=1;
							v[j].push(c[i]);
							pa.push_back({1,j});
//							cout<<1<<"   "<<j<<endl;
							bo1[j]=0;
							vv[j]++;
							break;
						}
					}
				}
				if (!bo)
				{
					for (int j=1;j<=n;j++)
					{
						if (vv[j])
						{
							x=v[j].top();
							if ((bo1[j]||vv[j]==1)&&a[x][b[x]]<a[c[i]][b[c[i]]])
							{
								bo=1;
								bo1[j]=1;
								bo2[c[i]]=bo2[x]=1;
								v[j].push(c[i]);
								pa.push_back({1,j});
//								cout<<1<<"   "<<j<<endl;
								vv[j]++;
								break;
							}
						}
					}
				}
				if (!bo)
				{
					for (int j=1;j<=n;j++)
					{
						if (!vv[j])
						{
							pa.push_back({1,j});
//							cout<<1<<"   "<<j<<endl;
							v[j].push(c[i]);
							vv[j]++;
							break;
						}
					}
				}
			}
			else
			{
				bo=0;
				if (bo2[c[i]]==1)
				{
					for (int j=1;j<=n;j++)
					{
						if (bo1[j]==3)
						{
							pa.push_back({1,j});
//							cout<<1<<"   "<<j<<endl;
							vv[j]++;
							v[j].push(c[i]);
							clear(j);
							bo=1;
							break;
						}
					}
					if (!bo)
					{
						for (int j=1;j<=n;j++)
						{
							if (!vv[j])
							{
								bo1[j]=3;
								vv[j]++;
								v[j].push(c[i]);
								pa.push_back({1,j});
//								cout<<1<<"  "<<j<<endl;
								clear(j);
								break;
							}
						}
					}
				}
				else
				{
					for (int j=1;j<=n;j++)
					{
	//					cout<<vv[j]<<endl;
						if (vv[j]&&v[j].top()==c[i])
						{
							pa.push_back({1,j});
//							cout<<1<<"   "<<j<<endl;
							v[j].pop();
							vv[j]--;
							break;
						}
					}
				}
				bo2[c[i]]=0;
			}
		}
		int l=pa.size();
		printf("%d\n",l);
		for (int i=0;i<l;i++)
		{
			if (pa[i].fi>1)
			{
				printf("2 %d %d\n",pa[i].fi,pa[i].se);
			}
			else printf("1 %d\n",pa[i].se);
		}
		pa.clear();
	}
	return 0;
}