#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 2000005, M = 305;
int T;
int n, m, k;
int a[N];
int top[M*2], but[M*2];
bool vis[M*2];
deque <int> vec[M];
struct node {
	int op, x, y;
	
	node (){}
	node (int _op, int _x, int _y) {
		op = _op, x = _x, y = _y;
	}
};
vector <node> ans;
set <int> S; //position of empty

void solve() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= m; ++i) scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i) vec[i].clear(), S.insert(i);
	ans.clear();
	for (int i = 1; i <= k; ++i) top[i] = but[i] = 0;
	for (int i = 1; i <= m; ++i) {
//		printf("i=%d top[a[i]]=%d\n", i, top[a[i]]);
		if (top[a[i]]) {
//			printf("%d\n", 666);
			ans.pb(node(1, top[a[i]], 0));
			vec[top[a[i]]].pop_back();
			if (!vec[top[a[i]]].size()) S.insert(top[a[i]]), but[a[i]] = 0;
			else top[vec[top[a[i]]].back()] = top[a[i]];
			top[a[i]] = 0, vis[a[i]] = 0;
			continue;
		}
		if (S.size()) {
//			printf("%d\n", 777);
			auto p = *S.begin();
			ans.pb(node(1, p, 0));
//			printf("%d\n", but[a[i]]);
			if (but[a[i]]) {
				ans.pb(node(2, p, but[a[i]]));
				vec[but[a[i]]].pop_front();
				but[vec[but[a[i]]].front()] = but[a[i]];
				but[a[i]] = 0, vis[a[i]] = 0;
			}
			else {
				vec[p].push_back(a[i]), vis[a[i]] = 1;
				top[a[i]] = but[a[i]] = p;
				S.erase(S.begin());
			}
			continue;
		}
//		printf("%d\n", 888);
		int banpos, j;
		for (j = i + 1; j <= m; ++j) {
			if (vis[a[j]]) break;
		}
		banpos = top[a[j]] ? top[a[j]] : but[a[j]];
//		printf("%d %d\n", banpos, j);
		int Pos = 1;
		for (int k = i; k < j; ++k) {
			if (Pos == banpos) ++Pos;
			ans.pb(node(1, Pos, 0));
			top[vec[Pos].back()] = 0;
			vec[Pos].push_back(a[k]), vis[a[k]] = 1;
			top[a[k]] = Pos;
			++Pos;
		}
		i = j - 1;
//		for (int _ = 1; _ <= n; ++_) {
//			for (int __ = 0; __ < vec[_].size(); ++__) printf("%d ", vec[_][__]);
////			for (auto x : vec[_]) printf("%d ", x);
//			printf("\n");
//		}
//		printf("\n");
	}
	printf("%d\n", ans.size());
	for (auto it : ans) {
		if (it.y) printf("%d %d %d\n", it.op, it.x, it.y);
		else printf("%d %d\n", it.op, it.x);
	}
}

int main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	scanf("%d", &T);
	while (T--) solve();
	return 0;
}
