#include <bits/stdc++.h>
using std::multiset;
using std::vector;
typedef long long LL;

const int MAXN = 600 + 5, MAXM = 2e6 + 5;
int n, m, k, a[MAXM], p[MAXM], Match[MAXM], book[MAXN], tp[MAXN];
struct node { int x, Top; bool operator <(const node &fir)const { return Top < fir.Top; } } ;

int Read()
{
	int sum = 0, fh = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) fh -= (ch == '-') << 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) sum = (sum << 3) + (sum << 1) + (ch ^ 48);
	return sum * fh;
}

void Solve()
{
	n = Read(), m = Read(), k = Read(); for (int i = 1; i <= m; ++i) a[i] = Read(), p[i] = Match[i] = 0;
	for (int i = 1; i <= n; ++i) tp[i] = 0;
	for (int i = 1; i <= k; ++i) book[i] = 0;
	for (int i = 1; i <= m; ++i)
	{
		if (book[a[i]] == 0) book[a[i]] = i;
		else { Match[i] = book[a[i]]; Match[book[a[i]]] = i; book[a[i]] = 0; }
	}
	for (int i = 1; i <= 30; ++i) std::cerr << Match[i] << " \n"[i == 13];
	multiset <node> s; vector <int> vopt, vfir, vsec;
	for (int i = 1; i <= n - 1; ++i) s.insert((node){i, 0});
	for (int i = 1; i <= m; ++i)
	{
		if (Match[i] < i)
		{
			int Num = p[Match[i]];
			vopt.push_back(1), vfir.push_back(n), vsec.push_back(0);
			vopt.push_back(2), vfir.push_back(n), vsec.push_back(Num);
			if (Match[tp[Num]] == i)
			{
				s.erase(s.find((node){Num, tp[Num]})); tp[Num] = 0;
				s.insert((node){Num, tp[Num]});
			}
		}
		else
		{
			node it = *s.begin(); s.erase(s.begin());
			vopt.push_back(1), vfir.push_back(it.x), vsec.push_back(0);
			p[i] = it.x; tp[it.x] = Match[i]; s.insert((node){it.x, tp[it.x]});
		}
	}
	printf("%d\n", (int)vopt.size());
	for (int i = 0; i < vopt.size(); ++i)
	{
		if (vopt[i] == 1) printf("%d %d\n", vopt[i], vfir[i]);
		else printf("%d %d %d\n", vopt[i], vfir[i], vsec[i]);
	}
}

int main()
{
	freopen("meow.in", "r", stdin); freopen("meow.out", "w", stdout);
	int t = Read(); while (t--) Solve(); return 0;
}