#include <bits/stdc++.h>
#define forn(i,s,t) for(int i=(s); i<=(t); ++i)
#define form(i,s,t) for(int i=(s); i>=(t); --i)
#define rep(i,s,t) for(int i=(s); i<(t); ++i)
typedef long long i64;
using namespace std;
const int Mod = 998244353;
const int N = 300 + 3, M = 2e6 + 2;
int n, m, k, a[M];
inline void init() {
}
namespace SUB1 {
set<int> S;
int up[N], dn[N], num[N], pos[N];
inline void ins(int i, int k) {
//	cout << "ins :: " << i << ' ' << k << '\n';
	if (k & 1) up[k >> 1] = a[i], num[k >> 1] ++ ;
	else dn[k >> 1] = a[i], S.insert(k | 1), num[k >> 1] ++ ;
	cout << "1 " << (k >> 1) << '\n';
}
inline void del(int i, int k) {
//	cout << "del :: " << i << ' ' << k << '\n';
	if (k & 1) {
		up[k >> 1] = 0, S.insert(k);
		cout << "1 " << (k >> 1) << '\n';
	} else {
		if (num[k >> 1] == 1) {
			dn[k >> 1] = 0, S.insert(k);
			cout << "1 " << (k >> 1) << '\n';
		} else {
			cout << "1 " << n << '\n';
			cout << "2 " << n << ' ' << (k >> 1) << '\n';
			dn[k >> 1] = up[k >> 1], up[k >> 1] = 0;
			pos[dn[k >> 1]] = k;
			S.insert(k + 1);
		}
	}
	num[k >> 1] -- ;
}
inline void solve1() {
	forn (i, 1, n) S.insert(i << 1);
	forn (i, 1, m) {
		if (pos[a[i]]) {
			del(a[i], pos[a[i]]);
			pos[a[i]] = 0;
		} else {
			pos[a[i]] = *S.begin();
			S.erase(S.begin());
			ins(i, pos[a[i]]);
		}
//		cout << "----------\n";
//		for (const int& v : S) cout << v << ' '; cout << '\n';
//		forn (j, 1, n) cout << up[j] << " \n"[j == n];
//		forn (j, 1, n) cout << dn[j] << " \n"[j == n];
//		cout << "--------------\n";
//		forn (j, 1, n) cout << pos[j] << " \n"[j == n];
	}
	S.clear();
}
	
}
inline void solve() {
	cin >> n >> m >> k;
	forn (i, 1, m) cin >> a[i];
	if (k == 2 * n - 2) SUB1 :: solve1();
}
int Trd;
int main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> Trd;
	while (Trd--) init(), solve();
	return 0;
}
/*
1
2 10 2
2 1 2 2 2 1 1 2 2 1
*/