#include <bits/stdc++.h>

#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define reset(x, v) memset(x, v, sizeof x)

using namespace std;

const int M = 2e6 + 5, N = 305, K = 610;

int n, m, k, a[M], pos[K], mp[4][N];
bool on[4][K];

struct Opt {
	int op, x, y;
} opt[M << 1];
int c;
inline void put(int x) { opt[++c] = {1, x, 0}; }
inline void del(int s1, int s2) { opt[++c] = {2, s1, s2}; }

void solve() {
	cin >> n >> m >> k;
	rep(i, 1, m) cin >> a[i];
	rep(i, 1, m) {
		int p = pos[a[i]];
		if (!p) {
			bool flag = false;
			rep(j, 1, n - 1) {
				if (!mp[1][j]) {
					put(j);
					mp[1][j] = a[i];
					on[1][a[i]] = true;
					pos[a[i]] = j;
					flag = true;
					break;
				}
			}
			if (flag) continue;
			rep(j, 1, n - 1) {
				if (!mp[2][j]) {
					put(j);
					mp[2][j] = a[i];
					on[2][a[i]] = true;
					pos[a[i]] = j;
					flag = true;
					break;
				}
			}
			if (flag) continue;
			rep(j, 1, k) {
				if (on[1][j] && a[i + 1] == j) {
					put(pos[j]);
					mp[3][pos[j]] = a[i];
					on[3][a[i]] = true;
					pos[a[i]] = j;
					break;
				}
				
			}
			continue;
		}
		if (on[1][a[i]]) {
			if (!mp[2][pos[a[i]]]) {
				put(p);
				pos[a[i]] = 0;
				continue;
			}
			put(n);
			del(p, n);
			pos[a[i]] = 0;
			on[1][a[i]] = false;
			if (mp[2][p]) {
				on[1][mp[2][p]] = true;
				on[2][mp[2][p]] = false;
			}
			if (mp[3][p]) {
				on[2][mp[3][p]] = true;
				on[3][mp[3][p]] = false;
			}
		} else if (on[2][a[i]]) {
			put(p);
			on[2][a[i]] = false;
			mp[2][p] = 0;
			pos[a[i]] = 0;
			if (mp[3][p]) {
				on[2][mp[3][p]] = true;
				on[3][mp[3][p]] = false;
			}
		} else if (on[3][a[i]]) {
			put(p);
			on[3][a[i]] = false;
			mp[3][p] = 0;
			pos[a[i]] = 0;
		}
		mp[2][p] = mp[3][p];
		mp[1][p] = mp[2][p];
		mp[3][p] = 0;
	}
	cout << c << '\n';
	rep(i, 1, c) {
		cout << opt[i].op << ' ';
		if (opt[i].op == 1) cout << opt[i].x << '\n';
		else cout << opt[i].x << ' ' << opt[i].y << '\n';
	}
}


signed main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	cin.tie(nullptr)->sync_with_stdio(false);
	int T;
	cin >> T;
	while (T--) {
		c = 0;
		reset(mp, 0);
		reset(pos, 0);
		reset(on, 0);
		solve();
	}
	return 0;
}
