#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <algorithm>

const int Maxm=2e6+7;
const int Maxn=607;

std::deque<int> stk[Maxn];
std::multiset<int> chk[Maxn];

struct Ans
{
	int x,y,z;
	
	Ans(){}
	Ans(int X,int Y,int Z=0):x(X),y(Y),z(Z){}
};

std::vector<Ans> res;
int n,m,k,opt,lst,c[Maxm],id[Maxm];

int cmp(const int i,const int j)
{
	return stk[i].size()>stk[j].size();
}

int T;

int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	
	scanf("%d",&T);
	
	while(T--)
	{
		scanf("%d%d%d",&n,&m,&k);
		
		for(int i=1;i<=m;++i)
			scanf("%d",&c[i]);
		
		for(int i=1;i<=n;++i)
			id[i]=i;
		
		for(int i=1;i<=m;++i)
		{
			bool flg=false;
			std::sort(id+1,id+n+1,cmp);
		
			lst=0;
			
			for(int i=1;i<=n;++i)
				if(stk[id[i]].size())
					lst=i;
			
			for(int j=1;j<=lst;++j)
				if(!stk[j].empty()&&stk[j].back()==c[i])
				{
					res.push_back(Ans(1,j));
					chk[j].erase(stk[j].back());
					stk[j].pop_back();
					++opt;
					flg=true;
					break;
				}
				else if(!stk[j].empty()&&lst<n&&stk[j].front()==c[i])
				{
					res.push_back(Ans(1,lst+1));
					res.push_back(Ans(2,j,lst+1));
					chk[j].erase(stk[j].front());
					stk[j].pop_front();
					opt+=2;
					flg=true;
					break;
				}
			
			if(flg)
				continue;
			
			int minop=1e9,minsz=1e9,k=0;
			
			std::sort(id+1,id+n+1,cmp);
			
			for(int i=1;i<=n;++i)
				if(stk[id[i]].size())
					lst=i;
			
			for(int j=1;j<=n;++j)
			{
				if(stk[j].empty())
					continue;
				int t=chk[j].count(c[i]);
				if(t<minop||(t==minop&&(int)stk[j].size()<minsz))
				{
					minsz=stk[j].size();
					minop=t;
					k=j;
				}
			}
			
			if(minop>0&&lst<n)
			{
				stk[++lst].push_back(c[i]);
				chk[lst].insert(c[i]);
				res.push_back(Ans(1,lst));
			}
			else
			{
				stk[k].push_back(c[i]);
				chk[k].insert(c[i]);
				res.push_back(Ans(1,k));
			}
		}
		
		bool flg=false;
		
		do
		{
			flg=false;
			
			for(int i=1;i<=n;++i)
				for(int j=i+1;j<=n;++j)
					if(!stk[i].empty()&&!stk[j].empty()&&stk[i].front()==stk[j].front())
					{
						flg=true;
						++opt;
						res.push_back(Ans(2,i,j));
						stk[i].pop_front();
						stk[j].pop_front();
					}
		}
		while(flg);
		
		for(int i=0;i<(int)res.size();++i)
			if(res[i].x==1)
				printf("1 %d\n",res[i].y);
			else
				printf("2 %d %d\n",res[i].y,res[i].z);
		
		res.clear();
		
		for(int i=1;i<=n;++i)	
			stk[i].clear(),chk[i].clear();
	}
}