#include <bits/stdc++.h>

int T;

namespace sub1 {
	#define N 505
	int f[N], g[N], sta[N][2];
	int id[N], p[N];
	void qwq () {
		while (T--) {
			int n, m, k;
			std::cin >> n >> m >> k;
			for (int i = 1; i <= n; i++)
				f[i] = 1, g[i] = 0, sta[i][0] = sta[i][1] = 0;
			for (int i = 1; i <= k; i++)
				id[i] = p[i] = 0;
			for (int i = 1; i <= m; i++) {
				int x;
				std::cin >> x;
				if (!p[x]) {
					int pos = -1;
					for (int j = 1; j <= n; j++) 
						if (f[j] || g[j]) {
							pos = j;
							break;
						}
					id[x] = pos;
					std::cout << 1 << ' ' << pos << '\n';
					if (f[pos]) {
						sta[pos][0] = x;
						p[x] = 2;
						f[pos] = 0, g[pos] = 1;
					}
					else if (g[pos]) {
						sta[pos][1] = x;
						p[sta[pos][0]] = 2;
						p[x] = 1;
						g[pos] = 0;
					}
				}
				else {
					if (p[x] == 1) {
						int pos = id[x];
						std::cout << 1 << ' ' << pos << '\n';
						p[x] = 0;
						g[pos] = 1;
					}
					else {
						int pos = id[x];
						int c = n;
						for (int j = 1; j <= n; j++) if (f[j]) {
							c = j; break;
						}
						std::cout << 1 << ' ' << c << '\n';
						std::cout << 2 << ' ' << pos << ' ' << c << '\n';
						p[x] = 0;
						if (g[pos]) g[pos] = 0, f[pos] = 1;
						else {
							sta[pos][0] = sta[pos][1];
							p[sta[pos][1]] = 2;
							g[pos] = 1;
						}
					}
				}
			}
		}
		return ;
	}
}

int main () {
	std::ios::sync_with_stdio (false);
	std::cin.tie (nullptr), std::cout.tie (nullptr);
	freopen ("meow.in", "r", stdin);
	freopen ("meow.out", "w", stdout);
	std::cin >> T;
	sub1::qwq ();
	return 0;
}