#include <bits/stdc++.h>

using namespace std;

const int M = 2e6 + 10;
int T, n, m, k;
int a[M], paired[M], lst[600];
int fronted[600], backed[600];
deque<int> stk[310];
queue<int> Zero;
priority_queue<pair<int, int> > s;
struct opr {
	int op, s1, s2;
	void set(int a, int b, int c) {
		op = a; s1 = b; s2 = c;
	}
} res[M << 1];

int ans;

int main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> T;
	while (T--) {
		cin >> n >> m >> k;
		for (int i = 1; i <= m; i++)
			cin >> a[i];
		memset(lst, 0, sizeof lst);
		memset(fronted, 0, sizeof fronted);
		memset(backed, 0, sizeof backed);
		ans = 0;
		for (int i = 1; i <= m; i++)
			if (!lst[a[i]])
				lst[a[i]] = i;
			else
				paired[lst[a[i]]] = i, paired[i] = -1, lst[a[i]] = 0;
		while (Zero.size()) Zero.pop();
		for (int i = 1; i <= n; i++)
			Zero.push(i);
		for (int i = 1; i <= m; i++) {
			if (fronted[a[i]]) {
				assert(stk[fronted[a[i]]].size());
				if (!Zero.empty()) {
					stk[fronted[a[i]]].pop_front();
					res[++ans].set(1, Zero.front(), 0);
					res[++ans].set(2, Zero.front(), fronted[a[i]]);
				} else {
					assert(stk[fronted[a[i]]].size() == 1);
					res[++ans].set(1, fronted[a[i]], 0);
					stk[fronted[a[i]]].pop_back();
				}
				if (stk[fronted[a[i]]].empty())
					Zero.push(fronted[a[i]]);
				else {
					fronted[a[stk[fronted[a[i]]].front()]] = fronted[a[i]];
					s.push({ paired[stk[fronted[a[i]]].back()], fronted[a[i]] });
				}
				fronted[a[i]] = backed[a[i]] = 0;
			} else if (backed[a[i]]) {
				assert(stk[backed[a[i]]].size());
				res[++ans].set(1, backed[a[i]], 0);
				stk[backed[a[i]]].pop_back();
				if (stk[backed[a[i]]].empty())
					Zero.push(backed[a[i]]);
				else
					backed[a[stk[backed[a[i]]].back()]] = backed[a[i]], s.push({ paired[stk[backed[a[i]]].back()], backed[a[i]] });
				fronted[a[i]] = backed[a[i]] = 0;
			} else if (Zero.size()) {
				s.push({ paired[i], Zero.front() });
				res[++ans].set(1, Zero.front(), 0);
				stk[Zero.front()].push_back(i);
				fronted[a[i]] = backed[a[i]] = Zero.front();
				Zero.pop();
			} else {
				while (s.size() && (stk[s.top().second].empty() || s.top().first != paired[stk[s.top().second].back()])) s.pop();
				assert(s.size() != 0);
				int tt = s.top().second;
				s.pop();
				res[++ans].set(1, tt, 0);
				stk[tt].push_back(i);
				backed[a[i]] = tt;
				s.push({ paired[i], tt });
			}
		}
		cout << ans << '\n';
		for (int i = 1; i <= ans; i++)
			if (res[i].op == 1)
				cout << 1 << ' ' << res[i].s1 << '\n';
			else
				cout << 2 << ' ' << res[i].s1 << ' ' << res[i].s2 << '\n';
	}
	return 0;
}