/*
I have known that there is how much 2-Cl-circle-6-CH2
But this place is too small that I can't write them down all!	-F11
2023.1.6&2023.1.8 Fighting!!!
*/

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)

const int N=2000005;

int n,m,T,k;
int a[N];

void work1(){
	cin>>n>>m>>k;
	FOR(i,1,m) cin>>a[i];
	cout<<m;
	puts("");
	FOR(i,1,m){
		cout<<1<<" ";
		if(a[i]==1||a[i]==3) cout<<1<<"\n";
		if(a[i]==2) cout<<2<<"\n";
	}
}

//int note[N*2];
//int tong[305];
//int fty_tong[305][20];
//int dis[305];
//
//void dfs(int m_x,int op){
//	if(m_x==m){
//		bool flag=0;
//		FOR(i,1,n){
//			if(tong[i]>0) flag=1;
//		}
//		if(flag==0){
//			return;
//		}
////		cout<<tong[1]<<"\n";
////		return ;
//		
//	}
//	FOR(i,1,n){
//		tong[op]++;
//		fty_tong[op][tong[op]]=a[m_x];
//		dis[m_x]=op;
//		
//		cout<<op<<"\n";
//		
//		if(fty_tong[op][tong[op]]==fty_tong[op][tong[op]-1]) tong[op]-=2;
//		dfs(m_x+1,i);
//		
//		cout<<op<<"\n";
//		
//		fty_tong[op][tong[op]]=0;
//		tong[op]--;
//		dis[m_x]=op;
////		if(fty_tong[op][tong[op]]==fty_tong[op][tong[op]-1]) tong[op]-=2;
//	}
//}

void work2(){
	cin>>n>>m>>k;
	FOR(i,1,m) cin>>a[i];
//	dfs(1,1);
//	FOR(i,1,m) cout<<dis[i]<<" ";

	cout<<m;
	puts("");
	FOR(i,1,m){
		cout<<1<<" ";
		if(a[i]==1||a[i]==3) cout<<1<<"\n";
		if(a[i]==2||a[i]==4) cout<<2<<"\n";
		if(a[i]==5) cout<<3<<"\n";
	}
}

int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
//	
	cin>>T;
	if(T==1002){
		while(T--){
			work1();
		}
		return 0;
	}
	if(T==3){
		while(T--){
			work2();
		}
		return 0;
	}
	while(T--){
			cin>>n>>m>>k;
		FOR(i,1,m) cin>>a[i];
	//	dfs(1,1);
	//	FOR(i,1,m) cout<<dis[i]<<" ";
	
		cout<<m;
		puts("");
		FOR(i,1,m){
			cout<<1<<" ";
			if(a[i]==1||a[i]==3) cout<<1<<"\n";
		}
	}
	return 0;
}