#include <bits/stdc++.h>

using namespace std;

int read() {
	int x=0, f=0; char c=getchar();
	while (!isdigit(c)) f|=c=='-', c=getchar();
	while (isdigit(c)) x=(x<<3)+(x<<1)+(c^48), c=getchar();
	return f ? -x : x;
}

const int N=2e6+10;
int n, m, k, a[N], pos[N], up[N], down[N];
set<pair<int, int> > s;

int main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	int T=read();
	while (T--) {
		n=read(), m=read(), k=read();
		for (int i=1; i<=m; i++) a[i]=read();
		s.clear();
		for (int i=1; i<=n; i++) s.insert({0, i});
		for (int i=1; i<=m; i++) {
			if (pos[a[i]]) {
				int p=abs(pos[a[i]]);
				if (pos[a[i]]>0) {
					printf("1 %d\n", p);
					s.erase({2, p});
					s.insert({1, p});
					up[p]=0;
					pos[a[i]]=0;
				}
				else if (!up[p]) {
					printf("1 %d\n", p);
					s.erase({1, p});
					s.insert({0, p});
					down[p]=0;
					pos[a[i]]=0;
				}
				else {
					auto t=*s.begin();
					printf("1 %d\n", t.second);
					printf("2 %d %d\n", p, t.second);
					pos[up[p]]=-p;
					down[p]=up[p];
					up[p]=0;
					pos[a[i]]=0;
					s.erase({2, p});
					s.insert({1, p});
				}
			}
			else {
				auto t=*s.begin();
				s.erase(t);
				auto w=*s.begin();
				if (w.first==0) {
					printf("1 %d\n", w.second);
					pos[a[i]]=-w.second;
					down[-pos[a[i]]]=a[i];
					s.erase(w);
					s.insert({1, w.second});
				}
				else {
					printf("1 %d\n", w.second);
					pos[a[i]]=w.second;
					up[pos[a[i]]]=a[i];
					s.erase(w);
					s.insert({2, w.second});
				}
				s.insert(t);
			}
		}
	}
	return 0;
}