#include <bits/stdc++.h>
using namespace std;
int a[2000010];
vector<int> poss[610];
int stk[310][5], len[310];
pair<int, int> pos[610]; // 0: top, 1: bot
inline void op1(int x)
{
	printf("1 %d\n", x);
}
inline void op2(int x, int e)
{
	printf("1 %d\n", e);
	printf("2 %d %d\n", x, e);
}
inline int nxt(int x, int pos)
{
	return *upper_bound(poss[x].begin(), poss[x].end(), pos);
}
int main()
{
//	freopen("B.in", "r", stdin);
//	freopen("B.out", "w", stdout);
	int T;
	scanf("%d", &T);
	while(T--)
	{
		int n, m, k;
		scanf("%d %d %d", &n, &m, &k);
		for(int i = 1; i <= k; i++)
			poss[i].clear(), pos[i] = {0, 0};
		for(int i = 1; i <= n; i++)
		{
			len[i] = 0;
			stk[i][0] = stk[i][1] = stk[i][2] = 0;
		}
		for(int i = 1; i <= m; i++)
			scanf("%d", &a[i]), poss[a[i]].push_back(i);
		set<int> emp, sz1, val;
		for(int i = 1; i <= n; i++)
			emp.insert(i);
		for(int i = 1; i <= m; i++)
		{
			int u = a[i];
			if(pos[u].first)
			{
				int p = pos[u].first;
				if(pos[u].second && len[p] > 1)
				{
					int e = *(emp.begin());
					op2(p, e);
					len[p]--;
					stk[p][0] = stk[p][1], stk[p][1] = stk[p][2], stk[p][2] = 0;
					pos[u] = {0, 0};
					if(len[p])
						pos[stk[p][0]] = {p, 1};
					if(!len[p])
						emp.insert(p), sz1.erase(p);
					if(len[p] == 1)
						sz1.insert(p), val.erase(p);
					if(len[p] == 2)
					{
						int x = stk[p][0], y = stk[p][1];
						if(nxt(x, i) < nxt(y, i))
							val.insert(p);
					}
				}
				else
				{
					op1(p);
					len[p]--, stk[p][len[p]] = 0;
					pos[u] = {0, 0};
					if(len[p] >= 2)
						pos[stk[p][len[p] - 1]] = {p, 0};
					if(!len[p])
						emp.insert(p), sz1.erase(p);
					if(len[p] == 1)
						sz1.insert(p), val.erase(p);
					if(len[p] == 2)
					{
						int x = stk[p][0], y = stk[p][1];
						if(nxt(x, i) < nxt(y, i))
							val.insert(p);
					}
				}
			}
			else
			{
				int e = *(emp.begin());
				if(!sz1.empty())
				{
					int p = *(sz1.begin());
					op1(p);
					stk[p][1] = u, len[p]++;
					pos[u] = {p, 0};
					sz1.erase(p);
					int x = stk[p][0], y = stk[p][1];
					if(nxt(x, i) < nxt(y, i))
						val.insert(p);
				}
				else if(emp.size() >= 2)
				{
					op1(e);
					stk[e][0] = u, len[e]++;
					pos[u] = {e, 1};
					emp.erase(e), sz1.insert(e);
				}
				else // all 2
				{
					int p = 0;
					if(!val.empty())
						p = *(val.begin());
					if(p)
					{
						op1(p);
						stk[p][2] = u, len[p]++;
						pos[u] = {p, 0};
					}
					else
					{
						op1(e);
						stk[e][0] = u, len[e]++;
						pos[u] = {e, 1};
						emp.erase(e), sz1.insert(e);
					}
				}
			}
		}
	}
	return 0;
}