#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;
int n,m,k,T,a,ans;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
deque<int> q[310];
signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	while(T--)
	{
		ans=0;
		n=read(),m=read(),k=read();
		for(int i=1;i<=m;i++)
		{
			int pd=0;
			a=read();
			for(int j=1;j<=n;j++)
			{
				if(q[j].size())
				{
					if(q[j].back()==a)
					{
						q[j].pop_back();
						pd=1;
						ans+=2;
						cout<<1<<" "<<j<<endl;
						break;
					}
				}
			}
			if(pd)
				continue;
			for(int j=1;j<=n;j++)
			{
				if(!q[j].size())
				{
					q[j].push_back(a);
					pd=1;
					cout<<1<<" "<<j<<endl;
					break;
				}
			}
			if(pd)
				continue;
			q[1].push_back(a);
			cout<<1<<" "<<1<<endl;
		}
		while(ans<m)
		{
			for(int i=1;i<n;i++)
			{
				for(int j=i+1;j<=n;j++)
				{
					if(q[i].size()&&q[j].size())
					{
						if(q[i].front()==q[j].front())
						{
							ans+=2;
							q[i].pop_front();
							q[j].pop_front();
							cout<<2<<" "<<i<<" "<<j<<endl;
						}
					}
				}
			}
		}
	}
	return 0;
}
