#include <bits/stdc++.h>
#define file(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)

const int N = 300 + 5;
const int M = 2e6 + 5;

int gMr;
int n, m, k;
int a[M];
int in[2 * N];
std::vector<std::string> ans;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while ('0' > ch or ch > '9') f = ch == '-' ? -1 : 1, ch = getchar();
	while ('0' <= ch and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return x * f;
}

std::string to_str(int x) {
	std::string res = "";
	while (x) {
		res = char(x % 10 + '0') + res;
		x /= 10;
	}
	return res;
}

std::deque<int> q[N];
void solve1() {
	for (int i = 1; i <= m; i ++) {
		bool f = 0;
		for (int j = 1; j <= n - 1; j ++) {
			if (q[j].empty())
				break;
			if (a[i] == q[j].back()) {
				ans.push_back("1 " + to_str(j)), q[j].pop_back();
				f = 1;
				break;
			} else if (a[i] == q[j].front()) {
				ans.push_back("1 " + to_str(n));
				ans.push_back("2 " + to_str(j) + " " + to_str(n));
				q[j].pop_front();
				f = 1;
				break;
			}
		}
		if (!f) {
			for (int j = 1; j <= n - 1; j ++) if (q[j].size() <= 1) {
				ans.push_back("1 " + to_str(j));
				q[j].push_back(a[i]);
				break;
			}
		}
	}
	printf("%d\n", ans.size());
	for (int i = 0; i < ans.size(); i ++)
		std::cout << ans[i] << "\n";
}

bool f = 0;
void dfs(int num, std::deque<int> q[], std::vector<std::string> ans) {
	if (num == m + 1) {
		int ttt = 0;
		for (int i = 1; i <= n; i ++)
			ttt += q[i].size();
		if (ttt) return;
		printf("%d\n", ans.size());
		for (int i = 0; i < ans.size(); i ++)
			std::cout << ans[i] << "\n";
		f = 1;
		return;
	}
	for (int i = 1; i <= n; i ++) {
		int tt = 0;
		std::deque<int> qq[N];
		for (int j = 1; j <= n; j ++)
			qq[j] = q[j];
		if (!qq[i].empty() and qq[i].back() == a[num])
			qq[i].pop_back();
		else
			qq[i].push_back(a[num]);
		ans.push_back("1 " + to_str(i)); tt ++;
		bool ff = 1;
		while (ff) {
			ff = 0;
			for (int j = 1; j <= n - 1; j ++) if (!qq[j].empty()) {
				for (k = j + 1; k <= n; k ++) if (!qq[k].empty())
					if (qq[j].front() == qq[k].front()) {
						ff = 1;
						ans.push_back("2 " + to_str(j) + " " + to_str(k)); tt ++;
						qq[j].pop_front();
						qq[k].pop_front();
						break;
					}
				if (ff)
					break;
			}
		}
		dfs(num + 1, qq, ans);
		if (f)
			return;
		while (tt --)
			ans.pop_back();
	}
}

int as[M];
void solve2() {
	dfs(1, q, ans);
}

int main() {
	file("meow");
	gMr = read();
	while (gMr --) {
		n = read(), m = read(), k = read();
		for (int i = 1; i <= m; i ++)
			a[i] = read();
		if (k == 2 * n - 2)
			solve1();
		else if (m <= 15)
			solve2();
		else
			solve1();
	}
	return 0;
}