#include <bits/stdc++.h>
using namespace std;

template <typename T>
inline void read(T &f) {
	f = 0; int fu = 0; char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') fu = 1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		f = f * 10 + c - '0';
		c = getchar();
	}
	if (fu) f = -f;
}

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

int op[N * 2], x[N * 2], y[N * 2], len;
int a[N];
int pos[M], posy[M], v[M][2], cnt[M], seq[M], cnt2[M], tp[M], vis[M];
int T, n, m, k, top, tmp;

void push(int v1, int v2, int v3 = 0) {
	++len;
	op[len] = v1; x[len] = v2; y[len] = v3;
}

deque <int> st[M];
void check() {
	int j = 1;
	for (int i = 1; i <= len; i++) {
		if (op[i] == 1) {
			int r = x[i], c = a[j]; ++j;
			assert(r >= 1 && r <= n);
			if (!st[r].empty() && st[r].back() == c) {
				st[r].pop_back();
			} else {
				st[r].push_back(c);
			}
		}
		if (op[i] == 2) {
			int l = x[i], r = y[i];
			assert(l != r && !st[l].empty() && !st[r].empty() && st[l].front() == st[r].front());
			st[l].pop_front(); st[r].pop_front();
		}
	}
	for (int i = 1; i <= n; i++) assert(st[i].empty());
}

int main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	read(T);
	while (T--) {
		memset(pos, 0, sizeof(pos));
		read(n); read(m); read(k);
		len = top = 0;
		for (int i = 1; i <= n - 1; i++) {
			for (int j = 0; j <= 1; j++) seq[++top] = i;
		}
		tmp = n;
		for (int i = 1; i <= m; i++) read(a[i]);
		for (int i = 1; i <= m; i++) {
			if (pos[a[i]]) {
				int r = pos[a[i]];
				if (posy[a[i]] == 1) {
					push(1, r);
					pos[a[i]] = 0;
					--cnt[r]; seq[++top] = r;
				} else {
					push(1, tmp);
					push(2, r, tmp);
					--cnt[r]; seq[++top] = r;
					pos[a[i]] = 0;
					if (cnt[r] == 1) {
						posy[v[r][1]] = 0;
					}
				}
			} else if (top) {
				int r = seq[top--];
				push(1, r);
				v[r][cnt[r]] = a[i];
				pos[a[i]] = r; posy[a[i]] = cnt[r];
				++cnt[r];
			} else {
				int j = i + 1, flag = 0;
				while (1) {
					if (a[j] == a[i]) {
						flag = 1;
						break;
					}
					if (posy[a[j]] == 0) {
						flag = 2;
						break;
					}
					cnt2[a[j]] ^= 1; ++j;
				}
				for (int k = i + 1; k <= j - 1; k++) tp[a[k]] = pos[a[k]];
				if (flag == 1) {
					push(1, tmp);
					for (int k = i + 1; k <= j - 1; k++) {
						int r = tp[a[k]];
						push(1, r);
						if (cnt[r] == 2) {
							--cnt[r]; pos[a[k]] = 0;
						} else {
							++cnt[r]; pos[a[k]] = r;
						}
					}
					push(1, tmp);
					for (int k = i + 1; k <= j - 1; k++) {
						int r = tp[a[k]];
						if (!vis[r] && cnt[r] == 1) {
							seq[++top] = r;
							vis[r] = 1;
						}
					}
				} else if (cnt2[v[pos[a[j]]][1]]) {
					push(1, tmp); pos[a[i]] = tmp; posy[a[i]] = 0; cnt[tmp] = 1;
					for (int k = i + 1; k <= j - 1; k++) {
						int r = tp[a[k]];
						push(1, r);
						if (cnt[r] == 2) {
							--cnt[r]; pos[a[k]] = 0;
						} else {
							++cnt[r]; pos[a[k]] = r;
						}
					}
					int r = pos[a[j]];
					push(1, r);
					cnt[r] = 0; pos[a[j]] = 0;
					for (int k = i + 1; k <= j - 1; k++) {
						int r = tp[a[k]];
						if (!vis[r] && cnt[r] == 1) {
							seq[++top] = r;
							vis[r] = 1;
						}
					}
					seq[++top] = tmp; tmp = r;
				} else {
					int r = pos[a[j]];
					push(1, r);
					for (int k = i + 1; k <= j - 1; k++) {
						int r = tp[a[k]];
						push(1, r);
						if (r == pos[a[j]]) {
							continue;
						}
						if (cnt[r] == 2) {
							--cnt[r]; pos[a[k]] = 0;
						} else {
							++cnt[r]; pos[a[k]] = r;
						}
					}
					push(1, tmp);
					push(2, r, tmp);
					pos[a[j]] = 0;
					for (int k = i + 1; k <= j - 1; k++) {
						int r = tp[a[k]];
						if (!vis[r] && cnt[r] == 1) {
							seq[++top] = r;
							vis[r] = 1;
						}
					}
					posy[v[r][1]] = 0;
					v[r][1] = a[i];
					pos[a[i]] = r; posy[a[i]] = 1;
				}
				for (int k = i + 1; k <= j - 1; k++) {
					vis[tp[a[k]]] = cnt2[a[k]] = 0;
				}
				i = j;
			}
		}
//		check();
		printf("%d\n", len);
		for (int i = 1; i <= len; i++) {
			if (op[i] == 1) {
				printf("%d %d\n", op[i], x[i]);
			} else {
				printf("%d %d %d\n", op[i], x[i], y[i]);
			}
		}
	}
//	fprintf(stderr, "ok\n");
	return 0;
}