/*
stuff the numbers randomly into the stack and keep these rules:
1. each stack could only stuff at most two elements except for the special case
2. we should keep stack from being half full as possibly
3. if the number next to be poped out is on the top of the stack (id) currently, then stack (id) can't stuff other elements before this number is poped out
4. if the number next to be poped out is on the bottom of the stack (id) currently, then stack (id) is allowed to stuff three elements and keep one stack empty. (special case)
*/
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
int T, n, m, k;
int a[2000010], sub[2000010];
// sub - the next number to be poped out
// cnt - the appearance times of current number
int in_stack[610];

int siz_stack[310], top_stack[310];
queue<int> q;
queue<int> qh;
// we said a stack is full that the stack has two elements, or three for the stack that the number next to be poped out is at the bottom of it)
// q - empty
// qh - half-empty (not empty and not full).
// ** It is possible to happen only after continuously using 2 to remove elements that qh's size is more than 1
int pos[610][3];
// pos[x][1] is regardless of the element next to be removed, while array size will count the element next to he removed.
int main(){
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	scanf("%d", &T);
	while(T--){
		scanf("%d%d%d", &n, &m, &k);
		for(int i = 1; i <= m; i++) scanf("%d", &a[i]);
		for(int i = 1; i <= n; i++) siz_stack[i] = 0;
		for(int i = 1; i <= k; i++) pos[i][0] = pos[i][1] = pos[i][2] = -1;
		for(int i = 1; i <= m; i++) in_stack[i] = 0;
		int lst = 0;
		for(int i = 1; i <= m; i++){
			in_stack[a[i]]++;
			if(in_stack[a[i]] % 2 == 0)
				sub[lst] = i, lst = i;
		}
		while(!q.empty()) q.pop();
		while(!qh.empty()) qh.pop();
		for(int i = 1; i <= n; i++)
			q.push(i);
		int cur_pop = a[sub[0]], cur_pop_pos = sub[0], cur_pop_stack = -1;
		for(int i = 1; i <= m; i++){
			int cur = a[i];
			if(cur == a[cur_pop] && pos[cur][0] != -1){
				int cur_popt_pos = sub[cur_pop_pos];
				int cur_popt = a[cur_popt_pos];
				int cur_popt_stack = pos[cur_popt][0];
				if(pos[cur][1] == 0){
					if(q.empty()) printf("error\n");
					// pop the bottom of stack (cur_pop_stack) and stack (q.front())
					if(siz_stack[cur_pop_stack] == 1){
						printf("1 %d\n", cur_pop_stack);
						top_stack[cur_pop_stack] = -1;
					}else{
						printf("1 %d\n", q.front());
						printf("2 %d %d\n", q.front(), cur_pop_stack);
					}
				}else{	// pos[cur][1] == 1
					printf("1 %d\n", cur_pop_stack);
				}
				siz_stack[cur_pop_stack]--;
				if(cur_pop_stack != cur_popt_stack){
					if(siz_stack[cur_pop_stack] == 0)
						q.push(cur_pop_stack);
					if(siz_stack[cur_pop_stack] == 1)
						q.push(cur_pop_stack);
				}
				for(int t = pos[cur_pop][2]; t != -1; t = pos[t][2])
					pos[t][1] -= 1;
				pos[cur_pop][0] = pos[cur_pop][1] = pos[cur_pop][2] = -1;
				cur_pop = cur_popt, cur_pop_stack = cur_popt_stack;
				int siz_qh = qh.size();
				for(int i = 0; i < siz_qh; i++){
					int t = qh.front(); qh.pop();
					if(t == cur_pop_stack) break;
					qh.push(t);
				}
			}else{
				if(!qh.empty() || cur_pop_stack != -1 && pos[cur_pop][1] == 0 && siz_stack[cur_pop_stack] < 3){
					int cur_stack;
					if(cur_pop_stack != -1 && pos[cur_pop][1] == 0 && siz_stack[cur_pop_stack] < 3)
						cur_stack = cur_pop_stack;
					else{
						cur_stack = qh.front();
						qh.pop();
					}
//					printf("!!%d %d\n", cur, cur_stack);
					pos[cur][0] = cur_stack;
					pos[cur][1] = siz_stack[cur_stack];
					pos[top_stack[cur_stack]][2] = cur; top_stack[cur_stack] = cur;
					siz_stack[cur_stack]++;
					printf("1 %d\n", cur_stack);
					if(cur == cur_pop) cur_pop_stack = cur_stack; 
				}else{
					int cur_stack = q.front(); q.pop();
					pos[cur][0] = cur_stack;
					pos[cur][1] = 0;
					printf("1 %d\n", cur_stack);
					siz_stack[cur_stack]++;
					if(cur == cur_pop) cur_pop_stack = cur_stack;
					              else qh.push(cur_stack);
				}
			}
/*			printf("-----------\n");
			printf("## %-3d %-3d\n", cur_pop, cur_pop_stack);
			for(int i = 1; i <= k; i++)
				printf("%-3d %-3d %-3d\n", pos[i][0], pos[i][1], pos[i][2]);
			printf("-----------\n");*/
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
