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

int inline read() {
	int x = 0; char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
	return x;
}

int T;
int n, m, k;
int a[2000005], tgt[2000005];
int sum[605];
int pos[605]; // 0 - not found, 1 ~ n - bottom, n + 1 ~ 2 * n - top
int flg[605];

vector<int> stk[305];
struct ops {
	int typ, v1, v2;
} ans[4000005]; int len;

int main() {
	freopen("meow2.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	
	T = read();
	while (T--) {
		n = read(), m = read(), k = read();
//		n = 2, m = 30000, k = 3;
//		for (int i = 1; i <= m; i++) a[i] = (i - 1) / 10000 + 1;
//		random_shuffle(a + 1, a + m + 1);
//		for (int i = 1; i <= m; i++) printf("%d ", a[i]);
		
		memset(sum + 1, 0, sizeof(int) * k);
		for (int i = 1; i <= m; i++) {
			a[i] = read();
			if (sum[a[i]]) tgt[i] = a[i];
			else tgt[i] = 0;
			sum[a[i]] ^= 1;
		}
		for (int i = m; i; i--)
			if (!tgt[i]) tgt[i] = tgt[i + 1];
		
		len = 0;
		for (int i = 1; i <= n; i++) stk[i].clear();
		int vac = 1;
		for (int i = 1; i <= m; i++) {
			int nowc = a[i], nowtgt = tgt[i];
			if (nowc != nowtgt) {
				int x = 0;
				for (int j = 1; j <= n; j++) if (j != vac)
					if (stk[j].size() < 2) { x = j; break; }
				if (x != 0) {
					ans[++len] = (ops){1, x, 0};
					pos[nowc] = stk[x].size() * n + x;
					stk[x].push_back(nowc);
				}
				else { // man yuan
					int j = i + 1; 
					for (; ; j++) {
						assert(tgt[j] > 0);
						flg[tgt[j]] = pos[tgt[j]];
//						if (i == 133) printf("Y %d %d %d\n", tgt[j], a[j], flg[tgt[j]]);
						if (pos[tgt[j]] <= n) break; // fu za du bao zha
					}
					assert(flg[nowc] == 0);
					if (pos[tgt[j]] == 0) {
						assert(tgt[j] == nowc); // shen me gui case a cao
						
						ans[++len] = (ops){1, vac, 0};
						stk[vac].push_back(nowc);
						pos[nowc] = vac;
						
						int ij = i + 1;
						for (; a[ij] != nowc; ij++) {
//							if (i == 133) printf("X %d %d %d %d\n", j, a[ij], pos[a[ij]], flg[a[ij]]);
							assert(flg[a[ij]]);
							if (pos[a[ij]] == 0) {
								ans[++len] = (ops){1, flg[a[ij]], 0},
								stk[flg[a[ij]]].push_back(a[ij]),
								pos[a[ij]] = flg[a[ij]] + n;
								assert(stk[flg[a[ij]]].size() == 2);
							}
							else 
								ans[++len] = (ops){1, flg[a[ij]], 0},
								stk[flg[a[ij]]].pop_back(),
								pos[a[ij]] = 0;
						}
						
						ans[++len] = (ops){1, vac, 0},
						stk[vac].pop_back(),
						pos[nowc] = 0;
						
						// fu yuan 
						for (j = i + 1; ; j++) {
							flg[tgt[j]] = 0;
							if (pos[tgt[j]] <= n) break;
						}
						
						i = ij;
					}
					else {
						// tou ding yi ge tgt hen nan shou
						int tgtx = tgt[j];
						assert(stk[pos[tgtx]].size() == 2);
						int tgty = stk[pos[tgtx]][1];
						if (!flg[tgty]) {
							ans[++len] = (ops){1, pos[tgtx], 0};
							stk[pos[tgtx]].push_back(nowc);
							pos[nowc] = pos[tgtx] + n + n;
							// fu yuan 
							for (j = i + 1; ; j++) {
								flg[tgt[j]] = 0;
								if (pos[tgt[j]] <= n) break;
							}
						}
						else {
//							printf("give up\n");
//							return 0;
							ans[++len] = (ops){1, vac, 0};
							stk[vac].push_back(nowc);
							pos[nowc] = vac;
							
							int ij = i + 1;
							for (; a[ij] != tgtx; ij++) {
								assert(flg[a[ij]]);
								if (pos[a[ij]] == 0) {
									ans[++len] = (ops){1, flg[a[ij]], 0},
									stk[flg[a[ij]]].push_back(a[ij]),
									pos[a[ij]] = flg[a[ij]] + n;
									assert(stk[flg[a[ij]]].size() == 2);
								}
								else 
									ans[++len] = (ops){1, flg[a[ij]], 0},
									stk[flg[a[ij]]].pop_back(),
									pos[a[ij]] = 0;
							}
							
							ans[++len] = (ops){1, flg[tgtx], 0},
							stk[flg[tgtx]].pop_back(),
							pos[tgtx] = 0;
							assert(stk[flg[tgtx]].size() == 0);
							vac = flg[tgtx];
							
							// fu yuan 
							for (j = i + 1; ; j++) {
								flg[tgt[j]] = 0;
								if (pos[tgt[j]] <= n) break;
							}
							
							i = ij;
//							printf("goto %d\n", ij + 1);
							assert(a[i] == tgtx);
						}
					}
				}
			}
			else {
				int tcol = (pos[nowc] - 1) % n + 1;
				if (pos[nowc] == 0) {
					ans[++len] = (ops){1, vac, 0}, stk[vac].push_back(nowc), pos[nowc] = vac;
				}
				else if (pos[nowc] > n || stk[tcol].size() == 1) {
					assert(stk[tcol].back() == nowc);
					ans[++len] = (ops){1, tcol, 0}, stk[tcol].pop_back(), pos[nowc] = 0;
				}
				else {
//					if (i == 34905) cerr << "qwq " << nowc << " " << pos[nowc];
//					if (!(stk[vac].size() == 0 || stk[vac][0] == nowc))
//						printf("qaq %d %d %d\n", i, vac, nowc);
					assert(stk[vac].size() == 0 || stk[vac][0] == nowc);
					assert(stk[tcol][0] == nowc);
					ans[++len] = (ops){1, vac, 0};
					if (tcol != vac) ans[++len] = (ops){2, tcol, vac};
					pos[nowc] = 0;
					for (int j = 0; j + 1 < stk[tcol].size(); j++) {
						stk[tcol][j] = stk[tcol][j + 1];
						assert(pos[stk[tcol][j]] == (j + 1) * n + tcol);
						pos[stk[tcol][j]] = j * n + tcol;
					}
					if (stk[tcol].size()) stk[tcol].pop_back();
				}
			}
//			if (1) {
//				for (int k = 1; k <= n; k++)
//					if (1 < stk[k].size())
//						printf("%d ", stk[k][1]);
//					else printf("-1 ");
//				printf("\n");
//				for (int k = 1; k <= n; k++)
//					if (0 < stk[k].size())
//						printf("%d ", stk[k][0]);
//					else printf("-1 ");
//				printf("\n\n");
//			}
		}
		printf("%d\n", len);
		for (int i = 1; i <= len; i++)
			if (ans[i].typ == 1) printf("1 %d\n", ans[i].v1);
			else printf("2 %d %d\n", ans[i].v1, ans[i].v2);
		
		for (int i = 1; i <= n; i++) stk[i].clear();
		int cnt = 0;
		for (int i = 1; i <= len; i++)
			if (ans[i].typ == 1) {
				cnt++;
				int u = ans[i].v1;
				if (stk[u].size() > 0 && stk[u].back() == a[cnt]) stk[u].pop_back();
				else stk[u].push_back(a[cnt]);
			}
			else {
				int u1 = ans[i].v1, u2 = ans[i].v2;
				if (stk[u1][0] == stk[u2][0]) {
					for (int j = 0; j + 1 < stk[u1].size(); j++)
						stk[u1][j] = stk[u1][j + 1];
					stk[u1].pop_back();
					for (int j = 0; j + 1 < stk[u2].size(); j++)
						stk[u2][j] = stk[u2][j + 1];
					stk[u2].pop_back();
				}
			}
		for (int i = 1; i <= n; i++) assert(stk[i].size() == 0);
	}
}