#include <bits/stdc++.h>
using namespace std;
const int N = 705, M = 2e6 + 5;
int a[M], n, m, K, pos[M], o[N], vis[N], bel[N], ok;
deque <int> q[N];
int stk[M], top;
struct node {int id, x, y;};
vector <node> vec;

void uuu() {
	top = ok = 0; vec.clear();
	pos[0] = n;
	fill(vis + 1, vis + 1 + K, 0);
	fill(pos + 1, pos + 1 + K, 0);
	iota(o + 1, o + 1 + K, 1); o[K + 1] = 0;
	fill(bel + 1, bel + 1 + K, 0);
	sort(o + 1, o + 1 + K, [&](int x, int y) {
		return pos[x] > pos[y];});
	for (int i = 1; i <= n; i++) q[i].clear();
	int now = 0;
	for (int i = 1; i <= n; i++) vis[o[i]] = 1;
	for (int i = n + 1; i <= K; i++) bel[o[i]] = i - n;
	for (int i = 1; i <= pos[o[n + 1]]; i++) {
		if (vis[a[i]]) {
			vec.push_back({1, n});
			if ((int)q[n].size() && q[n].back() == a[i]) q[n].pop_back();
			else q[n].push_back(a[i]);
		} else {
			vec.push_back({1, bel[a[i]]});
		}
	}
	for (int i = 1; i < n; i++) stk[++top] = i;
//	cerr << "q : "; for (auto it : q[n]) cerr << it << " "; cerr << endl;
//	for (int i = pos[o[n + 1]] + 1; i <= m; i++) cerr << a[i] << " ";
//	cerr << endl;
	for (int i = pos[o[n + 1]] + 1; i <= m; i++) {
//		cerr << i << " " << a[i] << endl;
//			cerr << "wwSIZE" << (int)q[5].size() << endl;
		if (!ok && (int)q[n].size() && a[i] == q[n].back()) {
			vec.push_back({1, n});
			q[n].pop_back();
		} else {
			if (!bel[a[i]]) bel[a[i]] = stk[top], top--;
			vec.push_back({1, bel[a[i]]});
//			if (!top) cerr << "wanle\n";
//			cerr << bel[a[i]] << endl;
//			cerr << "DEBUG1\n";
//			cerr << "SIZE" << (int)q[5].size() << endl;
			if ((int)q[bel[a[i]]].size() && q[bel[a[i]]].back() == a[i]) {
//				cerr << "DEBUG2\n";
				q[bel[a[i]]].pop_back();
				stk[++top] = bel[a[i]], bel[a[i]] = 0;
			} else if (!ok && bel[a[i]] != n && (int)q[n].size() && a[i] == q[n].front()) {
//				cerr << "DEBUG3\n";
				vec.push_back({2, bel[a[i]], n});
//			cerr << "SIZE2**" << (int)q[5].size() << endl;
				q[n].pop_front();
//			cerr << "SIZE3**" << (int)q[5].size() << endl;
				if ((int)q[n].size() == 0 && !ok) stk[++top] = n, ok = 1;
				stk[++top] = bel[a[i]], bel[a[i]] = 0;
			}
//	cerr << "DEBUG" << endl;
			while (!ok && (int)q[n].size() && bel[q[n].front()]) {
				int x = q[n].front();
				if (bel[x] == n || !q[bel[x]].size()) break;
				vec.push_back({2, bel[x], n});
				q[n].pop_front();
				q[bel[x]].pop_front();
				stk[++top] = bel[x], bel[x] = 0;
			}
		}
	}
	while (!ok && (int)q[n].size() && bel[q[n].front()]) {
		int x = q[n].front();
		if (bel[x] == n || !q[bel[x]].size()) break;
		vec.push_back({2, bel[x], n});
		q[n].pop_front();
		q[bel[x]].pop_front();
		stk[++top] = bel[x], bel[x] = 0;
	}
	cerr << ok << endl;
	printf("%d\n", (int)vec.size());
	for (auto x : vec) {
		if (x.id == 1) printf("%d %d\n", x.id, x.x);
		else printf("%d %d %d\n", x.id, x.x, x.y);
	}
	
}
void func() {
	top = ok = 0; vec.clear();
	scanf("%d%d%d", &n, &m, &K);
	for (int i = 1; i <= m; i++)
		scanf("%d", &a[i]), pos[a[i]] = i;
	for (int i = 1; i <= n; i++) q[i].clear();
	fill(bel + 1, bel + 1 + n, 0);
	if (K == 2 * n - 2) {
		for (int i = 1; i < n; i++) stk[++top] = i;
		for (int i = 1; i <= m; i++) {
			if (bel[a[i]]) {
				int x = bel[a[i]];
				if (q[x].front() == a[i]) {
					vec.push_back({1, n, 0});
					vec.push_back({2, x, n});
				} else if (q[x].back() == a[i]) {
					vec.push_back({1, x, 0});
					q[x].pop_back();
					stk[++top] = x, bel[x] = 0;
				}
			} else {
				while (q[stk[top]].size() == 2) top--;
				int x = stk[top];
				if (q[x].size() == 1) top--;
				bel[a[i]] = x;
				q[x].push_back(a[i]); vec.push_back({1, x, 0});
			}
		}
	} else {
		uuu();
//		for (int i = 1; i <= n; i++) stk[++top] = i;
//		for (int i = 1; i <= m; i++) {
////			printf("i = %d\n", i);
//			if (bel[a[i]]) {
//				int x = bel[a[i]];
//				if (q[x].back() == a[i]) {
//					vec.push_back({1, x, 0});
//					q[x].pop_back();
//				} else {
//					vec.push_back({1, stk[top], 0});
//					vec.push_back({2, stk[top], x});
//					q[x].pop_front();
//					if (!q[x].size()) stk[++top] = x;
//				}
//				bel[a[i]] = 0;
//			} else if (top == 1) {
//				int op = ((int)q[1].size()) ? 1 : 2;
//				if (a[i + 1] == q[op].back()) {
//					int x = stk[top]; top--;
//					vec.push_back({1, x, 0});
//					q[x].push_back(a[i]);
//				} else {
//					vec.push_back({1, op, 0});
//					q[op].push_back(a[i]);
//				}
//			} else {
//				vec.push_back({1, stk[top], 0});
//				q[stk[top]].push_back(a[i]); top--;
//			}
//		}
	}
	printf("%d\n", (int)vec.size());
	for (auto x : vec) {
		if (x.id == 1) printf("%d %d\n", x.id, x.x);
		else printf("%d %d %d\n", x.id, x.x, x.y);
	}
	
}
	
int main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	int T; scanf("%d", &T);
	while (T--) func();
	return 0;
}