#include <bits/stdc++.h>
#define re register
#define ll long long
using namespace std;
inline int read() {int ret = 0, flag = 1;char ch = getchar();while(ch < '0' || ch > '9') {if(ch == '-') flag = -1;ch = getchar();}while(ch >= '0' && ch <= '9') {ret = ret * 10 + ch - '0';ch = getchar();} return ret * flag;}
const int M = 2e6 + 15;
const int N = 300 + 15;



int a[M];
int n, m, k;
deque<int> q[N];
inline void op1(int x, int pos) {
	if(!q[x].size()) {
		q[x].push_back(a[pos]);
		printf("1 %d\n", x);
		return;
	}
	if(q[x].back() == a[pos]) q[x].pop_back();
	else q[x].push_back(a[pos]);
	printf("1 %d\n", x);
}
inline void op2(int x, int y) {
	if(q[x].front() != q[y].front()) return;
	q[x].pop_front();
	q[y].pop_front();
	printf("2 %d %d\n", x, y);
}


inline void solve1() {
	for (re int i=1; i<=m; i++) {
		int num = (a[i] + 1) >> 1;
		if(q[num].size() <= 1) op1(num, i);
		else if(q[num].back() == a[i]) op1(num, i);
		else {
			op1(n, i);
			op2(num, n);
		}
	}
}

inline void solve2() {
	for (re int i=1; i<=m; i++) {
		if(!q[1].size() && !q[2].size()) op1(1, i);
		else {
			if(q[1].size() && a[i] == q[1].back()) op1(1, i);
			else if(q[2].size() && a[i] == q[2].back()) op1(2, i);
			else if(q[1].size() && a[i] == q[1].front() && !q[2].size()) {
				op1(2, i);
				op2(1, 2);
			}
			else if(q[2].size() && a[i] == q[2].front() && !q[1].size()) {
				op1(1, i);
				op2(1, 2);
			}
			else {
				if(q[1].size() && a[i+1] == q[1].front()) op1(2, i);
				else if(q[2].size() && a[i+1] == q[2].front()) op1(1, i);
				else if(q[1].size() && a[i+1] == q[1].back() && !q[2].size()) {
					op1(1, i);
				}
				else if(q[2].size() && a[i+1] == q[2].back() && !q[1].size()) {
					op1(2, i);
				}
				else op1(1, i);
			}
		}
	}
	
}

int main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	int T = read();
	while(T --) {
		n = read(); m = read(); k = read();
		for (re int i=1; i<=m; i++) {
			a[i] = read();
		}
		
		if(k == 2 * n - 2) solve1();
		if(k == 2 * n - 1 && n == 2) solve2();
	}
	return 0;
}
