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

template<typename T>
ostream& operator<<(ostream& ost, const vector<T>& a) {
	bool first = true;
	for (const T& x : a) {
		if (!first) ost << ",";
		ost << x, first = false;
	}
	return ost;
}

void debug_out() { cerr << "\n"; }

template<typename U, typename... T>
void debug_out(const U& x, const T&... args) {
	cerr << " " << x;
	debug_out(args...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) // debuger

int main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt;
	cin >> tt;
	while (tt--) {
		int n, m, k;
		cin >> n >> m >> k;
		vector<int> a(m);
		for (int i = 0; i < m; ++i) cin >> a[i], --a[i];
		vector<int> vis(k, -1);
		vector<int> mat(m);
		for (int i = m - 1; i >= 0; --i) {
			if (!~vis[a[i]]) vis[a[i]] = i;
			else {
				mat[i] = vis[a[i]];
				vis[a[i]] = -1;
			}
		}
		vector<tuple<int, int, int>> ops;
		vector<int> sz(n, 0);
		vector<array<int, 3>> s(n, {-1, -1, -1});
		set<pair<int, int>> st;
		auto check = [&](int i) {
			if (sz[i] == 3) return;
			for (int j = 0; j < sz[i] - 1; ++j) if (mat[s[i][j]] > mat[s[i][j + 1]]) return;
			st.emplace(sz[i] ? mat[s[i][sz[i] - 1]] : -1, i);
		};
		for (int i = 0; i < n; ++i) check(i);
		for (int i = 0; i < m; ++i) {
			if (!~vis[a[i]]) {
				// assert(st.size());
				auto p = st.lower_bound(make_pair(mat[i], -1));
				if (p == st.end() or (p != st.begin() and ~prev(p)->first)) --p;
				auto [x, j] = *p;
				st.erase(p);
				s[j][sz[j]++] = i;
				check(j);
				vis[a[i]] = j;
				ops.emplace_back(1, j, -1);
			}
			else {
				int j = vis[a[i]];
				vis[a[i]] = -1;
				st.erase(make_pair(sz[j] ? mat[s[j][sz[j] - 1]] : -1, j));
				if (a[s[j][sz[j] - 1]] == a[i]) {
					--sz[j];
					ops.emplace_back(1, j, -1);
				}
				else {
					// assert(a[s[j][0]] == a[i]);
					auto [x, p] = *st.begin();
					// assert(x == -1);
					ops.emplace_back(1, p, -1);
					ops.emplace_back(2, p, j);
					for (int l = 0; l < sz[j] - 1; ++l) s[j][l] = s[j][l + 1];
					--sz[j];
				}
				check(j);
			}
		}
		cout << ops.size() << '\n';
		for (const auto& [t, u, v] : ops) {
			if (t == 1) cout << "1 " << u + 1 << '\n';
			else cout << "2 " << u + 1 << ' ' << v + 1 << '\n';
		}
	}
}
/*
		vector<deque<int>> q(n);
		int i = 0, cnt = 0;
		for (const auto& [t, u, v] : ops) {
			if (t == 1) {
				if (q[u].size() and (a[i] == q[u].back())) {
					q[u].pop_back();
					cnt += 2;
				}
				else q[u].push_back(a[i]);
				++i;
			}
			else {
				assert(q[u].size() and q[v].size() and q[u].front() == q[v].front());
				q[u].pop_front();
				q[v].pop_front();
				cnt += 2;
			}
		}
		assert(cnt == m);
		cerr << "OK!\n";
*/