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

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

int T, n, m, k, a[M], pos[N], op[N];
unordered_set<int> s[3];
deque<int> Q[N];

struct P {
	int op, a, b;
	P(int _op, int _a, int _b = 0) {
		op = _op, a = _a, b = _b;
	}
};

vector<P> ans;

inline void ers(int u) {
	s[Q[u].size()].erase(u);
}

inline void ins(int u) {
	s[Q[u].size()].insert(u);
}

inline void push(int x) {
//	assert(pos[x]);
	ers(pos[x]);
	ans.emplace_back(1, pos[x]);
//	assert(Q[pos[x]].back() == x);
	Q[pos[x]].pop_back();
	ins(pos[x]);
	pos[x] = op[x] = 0;
}

inline void tpush(int x) {
	if (pos[x]) {
		push(x);
	} else {
		int u = *s[1].begin();
		ers(u);
		Q[u].push_back(x);
		ans.emplace_back(1, u);
		pos[x] = u, op[x] = 1;
		ins(u);
	}
}

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

void print(int x) {
	if (x / 10)
		print(x / 10);
	putchar((x % 10) + '0');
}

void solve() {
	n = read(), m = read(), k = read();
	s[0].clear();
	s[1].clear();
	s[2].clear();
	ans.clear();
	for (int i = 1; i <= m; i++) a[i] = read();
	for (int i = 1; i <= n; i++) ins(i);
	for (int i = 1; i <= m; i++) {
//		printf("i = %d\n", i);
//		for (int j = 1; j <= n; j++) {
//			printf("Q[%d] : ", j);
//			for (int k = 0; k < (int)Q[j].size(); k++) {
//				int x = Q[j][k];
//				assert(pos[x] == j);
//				assert(op[x] == k);
//				printf("%d ", x);
//			}
//			puts("");
//		}

//		assert(!s[0].empty());
		if (pos[a[i]]) {
			if (op[a[i]] == Q[pos[a[i]]].size() - 1) {
				push(a[i]);
			} else {
				int p = pos[a[i]], u = *s[0].begin();
				ers(p);
				ans.emplace_back(1, u);
				ans.emplace_back(2, p, u);
				Q[p].pop_front();
				op[Q[p][0]]--;
				ins(pos[a[i]]);
				pos[a[i]] = op[a[i]] = 0;
			}
			continue;
		}
		if ((int)s[0].size() > 1) {
			int u = *s[0].begin();
			ers(u);
			Q[u].push_back(a[i]);
			ans.emplace_back(1, u);
			pos[a[i]] = u, op[a[i]] = 0;
			ins(u);
			continue;
		}
		if (!s[1].empty()) {
			int u = *s[1].begin();
			ers(u);
			Q[u].push_back(a[i]);
			ans.emplace_back(1, u);
			pos[a[i]] = u, op[a[i]] = 1;
			ins(u);
			continue;
		}
		
		int j = i + 1;
		while (pos[a[j]] && op[a[j]]) {
			j++;
		}
		
		if (a[j] == a[i]) {
			ans.emplace_back(1, *s[0].begin());
			for (int k = i + 1; k < j; k++) tpush(a[k]);
			ans.emplace_back(1, *s[0].begin());
			continue;
		}
		int p = pos[a[j]], u = *s[0].begin();
//		assert(Q[p].size() == 2);
		int xorcnt = 0;
		for (int k = i + 1; k < j; k++) {
			if (a[k] == Q[pos[a[j]]][1]) xorcnt ^= 1;
		}
		if (xorcnt == 0) {
			ans.emplace_back(1, p);
			pos[a[i]] = p, op[a[i]] = 1, Q[p].push_back(a[i]);
			
			for (int k = i + 1; k < j; k++) {
				if (a[k] == Q[pos[a[k]]][1]) ans.emplace_back(1, u);
				else tpush(a[k]);
			}
			ans.emplace_back(1, u);
			ans.emplace_back(2, p, u);
//			assert(Q[p].front() == a[j]);
			
			Q[p].pop_front();
			op[Q[p][0]]--;
			pos[a[j]] = op[a[j]] = 0;
		} else {
			int u = *s[0].begin();
			ers(u);
			ans.emplace_back(1, u);
			pos[a[i]] = u, op[a[i]] = 0;
			Q[u].push_back(a[i]);
			ins(u);
			
			for (int k = i + 1; k < j; k++) tpush(a[k]);
			
//			assert(Q[pos[a[j]]].size() == 1);
			push(a[j]);
			assert(!s[0].empty());
		}
		i = j;
	}
	print((int)ans.size());
	putchar('\n');
	for (auto p : ans) {
		if (p.op == 1) {
			putchar('1');
			putchar(' ');
			print(p.a);
			putchar('\n');
		} else {
			putchar('2');
			putchar(' ');
			print(p.a);
			putchar(' ');
			print(p.b);
			putchar('\n');
		}
	}
}

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