#include <bits/stdc++.h>

using namespace std;

namespace sub1 {
const int OP = 4000001;
const int M = 2000001;
const int N = 301;
const int K = 600;

struct res {
	int op, stt[OP][3];
	void clear() { op = 0; }
	void o1(int s) {
		stt[op][1] = s;
		stt[op++][0] = 1;
	}
	void o2(int s1, int s2) {
		stt[op][1] = s1;
		stt[op][2] = s2;
		stt[op++][0] = 2;
	}
	
	void print(int x) {
		if (x > 9) print(x / 10);
		putchar(x % 10 + '0');
	}
	
	void output() {
		print(op); putchar('\n');
		for (int i = 0; i < op; ++i)
			if (stt[i][0] == 1)
				putchar('1'), putchar(' '), print(stt[i][1]), putchar('\n'); else
				putchar('2'), putchar(' '), print(stt[i][1]), putchar(' '), print(stt[i][2]), putchar('\n');
	}
} ans;
queue<int> q;
deque<int> st[N];
vector<int> mbr[N];
int T, n, m, k, a[M], bel[K], spst;

void w1(deque<int>* st, int i) {
	if (!st[bel[i]].empty() && st[bel[i]].back() == i) {
		if (st[bel[i]].size() == 2) q.push(bel[i]);
		st[bel[i]].pop_back();
		ans.o1(bel[i]);
	} else if (st[bel[i]].size() == 2) {
		q.push(bel[i]);
		st[bel[i]].pop_front();
		ans.o1(spst);
		ans.o2(bel[i], spst);
	} else {
		st[bel[i]].push_back(i);
		ans.o1(bel[i]);
	}
}

void w2(deque<int>* st, int i, bool flag) {
	if (!st[bel[i]].empty() && st[bel[i]].back() == i) {
		if (flag) if (st[bel[i]].size() == 2) q.push(bel[i]);
		st[bel[i]].pop_back();
		if (flag) ans.o1(bel[i]);
	} else {
		st[bel[i]].push_back(i);
		if (flag) ans.o1(bel[i]);
	}
}

void main() {
	scanf("%d", &T);
	while (T--) {
		ans.clear();
		scanf("%d%d%d", &n, &m, &k);
		for (int i = 1; i <= m; ++i) scanf("%d", &a[i]);
		memset(bel, 0, sizeof(bel));
		q = queue<int>();
		for (int i = 1; i <= n; ++i) mbr[i].clear();
		for (int i = 1; i < n; ++i) q.push(i);
		spst = n;
		for (int t = 1, i; t <= m; ++t)
			if (bel[a[t]]) w1(st, a[t]); else {
				i = a[t];
				while (!q.empty() && st[q.front()].size() == 2) q.pop();
				if (!q.empty()) {
					bel[i] = q.front();
					for (int i : mbr[q.front()]) bel[i] = 0;
					mbr[q.front()].clear();
					mbr[q.front()].push_back(i);
					for (int i : st[q.front()]) {
						bel[i] = q.front();
						mbr[q.front()].push_back(i);
					}
					w1(st, i);
					continue;
				}
				bool flag = 0;
				for (int t1 = t + 1, j; (j = a[t1]) != i; ++t1) {
					if (j != st[bel[j]].front()) continue;
					int cnt = 0;
					for (int t2 = t + 1; t2 < t1; ++t2)
						if (bel[a[t2]] == bel[j])
							++cnt;
					if (cnt % 2 == 0) {
						ans.o1(bel[j]);
						st[bel[j]].push_back(i);
						for (int t2 = t + 1; t2 < t1; ++t2) w2(st, a[t2], 1);
						ans.o1(spst);
						ans.o2(bel[j], spst);
						st[bel[j]].pop_front();
						bel[i] = bel[j];
						mbr[bel[j]].clear();
						mbr[bel[j]].push_back(i);
						mbr[bel[j]].push_back(st[bel[j]].front());
						bel[j] = 0;
						t = t1;
					} else {
						int tmp1 = st[bel[j]].front(), tmp2 = st[bel[j]].back();
						ans.o1(spst);
						st[spst].push_back(i);
						for (int t2 = t + 1; t2 <= t1; ++t2) w2(st, a[t2], 1);
						bel[i] = spst;
						mbr[spst].push_back(i);
						spst = bel[j];
						bel[tmp1] = bel[tmp2] = 0;
						mbr[spst].clear();
						t = t1;
					}
					flag = 1;
					break;
				}
				if (flag) continue;
				ans.o1(spst);
				st[spst].push_back(i);
				for (int t1 = t + 1, j; (j = a[t1]) != i; ++t1) {
					t = t1;
					w2(st, j, 1);
				}
				ans.o1(spst);
				st[spst].pop_back();
				++t;
			}
		ans.output();
	}
}
}

int main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	sub1::main();
	fclose(stdin);
	fclose(stdout);
	return 0;
}
