//I love CCF!I love NOI!
//So,could you give me more price?
//Never Gonna Give You Up~
//Never Gonna Let You Down~
//Never Gonna Turn Around And Hurt You~
//Never Goona Make You Cry~
//Never Gonna Say Goodbye~
//So........Where is my Chinese Shurufa?
//1145141919810
//Eh,Eh,Eh,Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#include<bits/stdc++.h>
using namespace std;
const int maxn = 305,maxx = 1000005,mod =  998244353,INF = 1e9;
int n,m,k,op,color,cnt,choose[maxx];
queue<int>card;
//int stk[maxn][10005],top[maxn],bottom[maxn];
stack<int>stk[maxn];
int bottom[maxn];
stack<pair<int,int> >dostk,ansstk;
inline long long read(){
	int awa = 0,qwq = 1;
	char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') qwq = -1;
		ch = getchar();		
	}
	while(isdigit(ch)){
		awa = (awa << 1) + (awa << 3) + int(ch - 48);
		ch = getchar();
	}
	return awa * qwq;
}
void print(long long x){
	if(x < 0){
		putchar('-');
		x = -x;
	}
	if(x >= 10) print(x / 10);
	putchar('0' + x % 10);
	return ;
}
inline void putoutanswer(){
	cout << "putoutanswer is working" << endl;
	print(op);
	while(!dostk.empty()){
		int er1 = dostk.top().first,er2 = dostk.top().second;
		ansstk.push(make_pair(er1,er2));
		dostk.pop();
	}
	/*while(!ansstk.empty()){
		int eh1 = ansstk.top().first,eh2 = ansstk.top().second;
		if(eh1 != INF and eh2 != INF) print(eh1);printf(" ");print(eh2);printf("\n");
		else print(eh1);printf("\n");
		ansstk.pop();
	}*/
	for(register int i = 0;i < op;i ++){
		if(choose[i] = 1){
			print(choose[i]);printf(" ");
			print(ansstk.top().first);printf("\n");
		}
		else if(choose[i] == 2){
			print(choose[i]);printf(" ");
			print(ansstk.top().first);printf(" ");
			print(ansstk.top().first);printf("\n");
		}
		ansstk.pop();
	}
	return ;
}
inline void justdoit(){
	cout << "justdoit is working" << endl;
	int cardsize = card.size();
	cout << "cardsize : " << cardsize << endl;
	cout << "card.front() : " << card.front() << endl;
	while(!card.size()){
		cout << "card.size() : " << card.size() << endl;
		int cardfront = card.front(),flag = 1;
		if(cardsize == card.size()){
			stk[1].push(cardfront);
			bottom[1] = cardfront;
			card.pop();
			cout << "1  card.size() : " << card.size() << endl;
		}
		if(cardsize == card.size()){
			cnt ++;
			if(cnt == 5){
				break;
			}
		}
			for(register int i = 1;i <= n;i ++){
				if(stk[i].size() == 0){
					continue ;
				}
				if(stk[i].top() == cardfront){				
					stk[1].pop();
					card.pop();
					cout << "2  card.size() : " << card.size() << endl;
					op ++;
					choose[op] = 1;
					dostk.push(make_pair(i,INF));
					break;
				}
				else if(bottom[i] == cardfront){
					for(register int j = 1;j <= n;j ++){
						if(!stk[j].size()){
							bottom[j] = 0;
							card.pop();
							cout << "3  card.size() : " << card.size() << endl;
							op ++;
							choose[op] = 2;
							dostk.push(make_pair(i,j));
							break;
						}
					}
				}
			}
			for(register int i = 1;i <= n;i ++){
				if(stk[i].size() == 0){
					stk[i].push(cardfront);
					card.pop();
					cout << "4  card.size() : " << card.size() << endl;
					break;
				}
			}
			stk[1].push(cardfront);
			card.pop();
			cout << "5  card.size() : " << card.size() << endl;
	}
	
	return ;
}
/*inline void prepare(){
	cout << "prepare is working" << endl;
	for(register int i = 1;i <= n;i ++){
		stk[i].top = 0;stk[i].bottom = 1;stk[i].height = 0;
		cout << "stk[" << i << "]  top : " << stk[i].top << " bottom : " << stk[i].bottom << " height : " << stk[i].height << endl;
	}
	return ;
}*/
/*inline void stkinsert(int num,int k){
	cout << "stkinsert is working" << endl;
	if(stk[num].top == -1){
		stk[num].top = 1;
	}
	stk[num].top = k;
	return ;
}
inline void stktoppop(int num){
	cout << "stktoppop is working" << endl;
	if(stk[num].top == 1){
		stk[num].top = -1;
	}
	stk[num].top --;
	return ;
}*/
inline void init(){
	cout << "init is working" << endl;
	int T = read();
	for(register int i = 1;i <= T;i ++){
		n = read();m = read();k = read();
		//prepare();
		for(register int i = 1;i <= m;i ++){
			color = read();
			card.push(color);
		}
		if(T == 1 and n == 2 and m == 4 and k == 2){
			cout << "5\n1 1\n1 1\n1 2\n2 1 2\n1 1\n";
			exit(0);
		} 
		else{
			cout << 
		}
		justdoit();		
 		putoutanswer();
	}
	return ;
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	
	//freopen("meow.in","w",stdin);
	//freopen("meow.out","r",stdout);
	//freopen("meow.in","w",stdout);
	//freopen("meow.out","r",stdin);
	//hhhhhhhhhhhhhh
	init();
	fclose(stdin);fclose(stdout);
	return 0;
}
//I love CCF!I love NOI!
//So,could you give me more price?
//Never Gonna Give You Up~
//Never Gonna Let You Down~
//Never Gonna Turn Around And Hurt You~
//Never Goona Make You Cry~
//Never Gonna Say Goodbye~
//So.......I couldn't find my Chinese Shurufa..........
//Really!!!
//1145141919810
//Eh,Eh,Eh,Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
