#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;

const int N = 605, M = 2e6 + 5;

int n, m, K;
int a[M];
int pos[N];
int sz[N];
int e[N][2];
int nxt[N], lst[N];

struct BBD
{
	int ty, x, y;
};
vector<BBD> U[N];

void task()
{
	scanf("%d%d%d", &n, &m, &K);
	for (int i = 1; i <= m; i++)
		scanf("%d", &a[i]);
	for (int i = 1; i <= K; i++) lst[i] = pos[i] = 0;
	for (int i = m; i >= 1; i--)
	{
		nxt[i] = lst[a[i]];
		lst[a[i]] = i;
	}
	for (int i = 1; i <= m; i++)
		vector<BBD>().swap(U[i]);
	int xus = n;
	bool fl = 1;
	vector<BBD> ans;
	vi s0, s1, s2;
	for (int i = 1; i <= n; i++)
	{
		sz[i] = 0;
		s0.push_back(i);
	}
	auto free = [&](int x)
	{
		ans.push_back({1, xus, 0});
		ans.push_back({2, xus, x});
		for (auto k : U[e[x][0]])
			ans.push_back(k);
		vector<BBD>().swap(U[e[x][0]]);		
	};
	auto del = [&](int x)
	{
		if (!sz[xus]) free(x);
		else 
		{
			U[e[xus][0]].push_back({2, xus, x});	
			for (auto k : U[e[x][0]])
				U[e[xus][0]].push_back(k);
			vector<BBD>().swap(U[e[x][0]]);		
		}
	};
	for (int i = 1; i <= m; i++)
	{
		if (pos[a[i]])
		{
			int x = pos[a[i]];
			if (sz[x] == 1)
			{
				if (U[e[x][0]].empty())
					ans.push_back({1, x, 0});
				else
					free(x);
				sz[x] = 0;
				s0.push_back(x);
				if (sz[xus]) xus = x;
			}
			else
			{
				if (a[e[x][0]] == a[i]) 
				{
					if (!sz[xus]) free(x);
					else U[e[xus][0]].push_back({2, xus, x});
					e[x][0] = e[x][1];
				}
				else ans.push_back({1, x, 0});
				sz[x] = 1;
				s1.push_back(x);
			}
			pos[a[i]] = 0;
			continue;
		}
		while (!s0.empty() && (sz[s0.back()] != 0 || s0.back() == xus)) s0.pop_back();
		if (!s0.empty())
		{
			int x = s0.back(); s0.pop_back();
			pos[a[i]] = x;
			e[x][0] = i;
			sz[x]++;			
		}
		else
		{
			while (!s1.empty() && (sz[s1.back()] != 1 || s1.back() == xus)) s1.pop_back();
			if (!s1.empty())
			{
				int x = s1.back(); s1.pop_back();
				pos[a[i]] = x;
				e[x][1] = i;
				sz[x]++;
			}
			else
			{
				while (!s2.empty() && (sz[s2.back()] != 2 || s2.back() == xus)) s2.pop_back();
				int x = s2.back();
				if (a[i] == a[i + 1])
				{
					ans.push_back({1, x, 0});
					ans.push_back({1, x, 0});
				}
				else
				{
					x = pos[a[i + 1]];
					if (a[e[x][0]] == x)
					{
						
					}
				}
			}
		}
	}
}

int main()
{
	int T;
	scanf("%d", &T);
	while (T--) task();
}