#include <bits/stdc++.h>
namespace Qiaoqia { 
constexpr int N = 605, U = 1, D = 2;

int n, m, k, pos[N], ud[N], tpo[N], lst;
std::deque<int> dq[N];
std::set<int> s;
std::vector<std::tuple<int, int, int>> ans;

void ord(int x) {
// 	std::cerr << x << "&\n";
	if (dq[x].size()) ud[dq[x][0]] = D;
	if (dq[x].size() > 1) ud[dq[x].back()] = U;
}

void opt(int op, int x, int y) {
	if (op == 1) {
// 		std::cerr << op << ' ' << x << ' ' << y << "#\n";
		ans.emplace_back(1, x, 0);
		if (dq[x].size() && dq[x].back() == y) {
			dq[x].pop_back(), pos[y] = 0;
			if (dq[x].size() < 2) s.insert(x);
		}
		else {
			dq[x].push_back(y);
			if (x != lst) pos[y] = x;
			ord(x);
		}
	}
	else {
		assert(dq[x].size() && dq[y].size());
		assert(dq[x][0] == dq[y][0]);
		ans.emplace_back(2, x, y);
// 		std::cerr << op << ' ' << x << ' ' << y << "%\n";
		pos[dq[x][0]] = 0;
		dq[x].pop_front(), dq[y].pop_front();
		if (x != lst && dq[x].size() < 2) s.insert(x);
		if (y != lst && dq[y].size() < 2) s.insert(y);
		ord(x), ord(y);
	}
}

void print() {
	std::cout << ans.size() << '\n';
	for (auto c : ans) {
		int op, x, y;
		std::tie(op, x, y) = c;
		if (op == 1) std::cout << "1 " << x << '\n';
		else std::cout << "2 " << x << ' ' << y << '\n';
	}
}

void solve() {
	std::cin >> n >> m >> k;
	std::vector<int> cd(m + 1);
	for (int i = 1; i <= m; i++) std::cin >> cd[i];
	for (int i = 1; i <= k; i++) pos[i] = 0, ud[i] = 0;
	for (int i = 1; i <= n; i++) dq[i].clear();
	ans.clear();	
	s.clear();
	if (n == 1) {
		for (int i = 1; i <= m; i++)
			opt(1, 1, cd[i]);
		print();
		return;
	}
	for (int i = 1; i < n; i++) s.insert(i);
	lst = n;
	for (int i = 1; i <= m; i++) {
		int c = cd[i];
		if (pos[c] != 0) {
			if (ud[c] == U) opt(1, pos[c], c);
			else opt(1, lst, c), opt(2, pos[c], lst);
		    pos[c] = 0; 
		}
		else if (s.size()) {
// 			int g = q.front(); q.pop();
// 			while (dq[g].size() >= 2) g = q.front(), q.pop();
			int g = *s.begin(); s.erase(s.begin());
// 			assert(g != -1);
			opt(1, g, c); 
			if (dq[g].size() < 2) s.insert(g);
		}
		else {
// 			assert(0);
			std::vector<int> tmp;
			int to = i;
			for (int j = i + 1; j <= m; j++) {
				tmp.push_back(cd[j]), to = j;
				if (ud[cd[j]] == D) break;
			}
			int dx = tmp.back(), cpd = 0;
			for (int j : tmp)
				if (j != dx && pos[j] == pos[dx]) cpd ^= 1;
			for (int j : tmp) tpo[j] = pos[j];
			if (cpd) {
				opt(1, lst, c);
				for (int j : tmp)
					if (j != dx) {
						if (j != c) opt(1, tpo[j], j);
						else opt(1, lst, c);
					}
				opt(1, pos[dx], dx), lst = pos[dx];
			}
			else {
				opt(1, pos[dx], c);
				for (int j : tmp) {
					if (j == dx) continue;
					if (tpo[j] == tpo[dx]) opt(1, lst, j);
					else opt(1, tpo[j], j);
				}
				opt(1, lst, dx), opt(2, lst, pos[dx]);
			}
			i = to;
		}
		// debug
// 		for (int j = 1; j <= n; j++) {
// 			std::cerr << '[';
// 			for (int t : dq[j]) std::cerr << t << ", ";
// 			std::cerr << "], ";
// 		}
// 		std::cerr << '\n';
	}
// 	for (int i = 1; i <= n; i++) assert(dq[i].empty());
	print();
}

void main() {
	int T;
	std::cin >> T;
	while (T--) solve();
}
}
void _() { std::ios::sync_with_stdio(false), std::cin.tie(nullptr); }
int main() { void IO(); IO(); _(); Qiaoqia::main(); }
void IO() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
}

// checklist completed at 0320K
