#include<bits/stdc++.h>
using namespace std;

//#define int long long

template<class T>
inline bool read(T &x){
	x=0;char ch;bool f=0;
	for(ch=getchar();!isdigit(ch);ch=getchar()){
		if(ch==EOF)return 0;
		if(ch=='-')f=1;
	}
	for (;isdigit(ch);ch=getchar()){
		x=(x<<1)+(x<<3)+(ch^48);
	}
	if(f)x=-x;
	return 1;
} 

template<class T>
void write(T x){
	if(x<0){
		putchar('-');
		write(-x);
		return ;
	}
	if(x>9)write(x/10);
	putchar(x%10|48);
}

template<class T>
inline void writeln(T x){
	write(x);putchar('\n');
}

template<class T>
inline void writespace(T x){
	write(x);putchar(' ');
}

int T,n,m,k,a[2000010];
bool f[2000010];
int op,siz[2000010],top[2000010];

void sub1(){
	for(register int i=1;i<=m;++i){
		int tmp=(a[i]+1)/2;
		if(!f[a[i]]){
			++op;++siz[tmp],top[tmp]=a[i];f[a[i]]=1;
		}
		else{
			if(top[tmp]==a[i]){
				++op;
				--siz[tmp];
				if(siz[tmp])top[tmp]=4*tmp-1-a[i];
				else top[tmp]=0;
				f[a[i]]=0;
			}
			else{
				op+=2;
				--siz[tmp];
				f[a[i]]=0;
			}
		}
	}
	writeln(op);
	for(register int i=1;i<=m;++i){
		int tmp=(a[i]+1)/2;
		if(!f[a[i]]){
			cout<<1<<" "<<tmp<<endl;
			++siz[tmp],top[tmp]=a[i];f[a[i]]=1;
		}
		else{
			if(top[tmp]==a[i]){
				cout<<1<<" "<<tmp<<endl;
				--siz[tmp];
				if(siz[tmp])top[tmp]=4*tmp-1-a[i];
				else top[tmp]=0;
				f[a[i]]=0;
			}
			else{
				cout<<1<<" "<<n<<endl;
				cout<<2<<" "<<tmp<<" "<<n<<endl;
				--siz[tmp];
				f[a[i]]=0;
			}
		}
	}
}

void sub2(){
	
}

signed main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	read(T);
	while(T--){
		memset(a,0,sizeof(a));op=0;
		read(n);read(m);read(k);
		for(register int i=1;i<=m;++i)read(a[i]);
		if(k==2*n-2){
			sub1();
		}else{
			sub2();
		}
	}
	return 0;
}