#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#define int long long
using namespace std;
const int N=3005,M=2e6+5,mod=998244353;

int read(){
	char c=getchar();int f=1,x=0;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-48;c=getchar();}
	return x*f;
}

int t,n,m,k,cnt,a[M],stack[305][N],top[M],bot[M],siz[M];
struct anss{
	int op,s1,s2;
}ans[N];

void work1(){
//	cout<<t<<endl;
	while(t--){
		memset(stack,0,sizeof (stack));
		memset(top,0,sizeof(top));
		memset(siz,0,sizeof(siz));
		memset(bot,0,sizeof(bot));
		cnt=0;
//		cout<<1<<endl;
		n=read(),m=read(),k=read();
		int qwq=k/(n-1);
		for(int i=1;i<=m;++i){
			a[i]=read();
			int pos;
			if(a[i]%2==0)pos=a[i]/qwq;
			else pos=a[i]/qwq+1;
//			cout<<pos<<endl;
			if(siz[pos]==0){
				top[pos]++;
				siz[pos]=1;
				bot[pos]=top[pos];
				stack[pos][top[pos]]=a[i];
				ans[++cnt].op=1;
				ans[cnt].s1=pos;
			}
			else{
//				cout<<bot[pos]<<endl;
//				cout<<stack[bot[pos]]<<endl;
//				cout<<endl;
//cout<<i<<" "<<pos<<endl;
				if(stack[pos][top[pos]]==a[i]){
					ans[++cnt].op=1;
					ans[cnt].s1=pos;
					stack[pos][top[pos]]=0;
					siz[pos]--;
					if(bot[pos]==top[pos])bot[pos]--;
					top[pos]--;
				}
				else if(a[i]==stack[pos][bot[pos]]){
					ans[++cnt].op=1;
					ans[cnt].s1=n;
					ans[++cnt].op==2;
					ans[cnt].s1=pos,ans[cnt].s2=n;
//					cout<<n<<endl;
					stack[pos][bot[pos]]=0;
					if(top[pos]==bot[pos])top[pos]++;
					siz[pos]--;
					bot[pos]++;
				}
				else{
					ans[++cnt].op=1;
					ans[cnt].s1=pos;
					top[pos]++;
					stack[pos][top[pos]]=a[i];
					siz[pos]++;
				}
			}
		}
		printf("%lld\n",cnt);
		for(int i=1;i<=cnt;++i){
			if(ans[i].op==1)printf("%lld %lld\n",ans[i].op,ans[i].s1);
			else printf("2 %lld %lld\n",ans[i].s1,ans[i].s2);
		}
	}
}
/*
4
3 8 5
1 2 3 4 3 4 2 1
*/
int ctim[N];
deque<int> q1,q2,q3;
void work2(){
	while(t--){
		n=read(),m=read(),k=read();
		while(!q1.empty())q1.pop_back();
		for(int i=1;i<=m;++i)a[i]=read();
		for(int i=1;i<=m;++i){
			if(ctim[a[i]]==0){
				ctim[a[i]]++;
				q1.push_back(a[i]);
				ans[++cnt].op=1;
				ans[cnt].s1=1;
//				cout<<q1.front()<<endl;
				continue;
			}
//			cout<<1<<endl;
			if(!q1.empty()&&q3.empty()){
				if(q1.front()==a[i]){
					q1.pop_front();
					ans[++cnt].op=1;
					ans[cnt].s1=3;
					ans[++cnt].op=2;
					ans[cnt].s1=1,ans[cnt].s2=3;
					continue;
				}
			}
			if(!q2.empty()&&q3.empty()){
				if(q2.front()==a[i]){
					q2.pop_front();
					ans[++cnt].op=1;
					ans[cnt].s1=3;
					ans[++cnt].op=2;
					ans[cnt].s1=1,ans[cnt].s2=3;
					continue;
				}
			}
			if(a[i]==q1.back()){
				q1.pop_back();
				ans[++cnt].op=1;
				ans[cnt].s1=1;
				continue;
			}
			if(a[i]==q2.back()){
				q2.pop_back();
				ans[++cnt].op=1;
				ans[cnt].s1=2;
				continue;
			}
			if(ctim[a[i]]%2==0){
				ctim[a[i]]++;
				q1.push_back(a[i]);
				ans[++cnt].op=1;
				ans[cnt].s1=1;
//				cout<<q1.front()<<endl;
			}
			else{
				ctim[a[i]]++;
				q2.push_back(a[i]);
				ans[++cnt].op=1;
				ans[cnt].s1=2;
			}
		}
		printf("%lld\n",cnt);
		for(int i=1;i<=cnt;++i){
			if(ans[i].op==1)printf("1 %lld\n",ans[i].s1);
			else printf("2 %lld %lld\n",ans[i].s1,ans[i].s2);
		}
	}
}

void work3(){
	while(t--){
		n=read(),m=read(),k=read();
//		cout<<n<<endl;
		while(!q1.empty())q1.pop_back();
		while(!q2.empty())q2.pop_back();
		for(int i=1;i<=m;++i){
			a[i]=read();
			if(q1.empty()){
				ans[++cnt].op=1;
				ans[cnt].s1=1;
				q1.push_back(a[i]);
				continue;
			}
			if(q1.back()==a[i]){
				ans[++cnt].op=1;
				ans[cnt].s1=1;
//				q1.push_back(a[i])
				q1.pop_back();
				continue;
			}
			if(q1.front()==a[i]){
				ans[++cnt].op=1;
				ans[cnt].s1=2;
				ans[++cnt].op=2;
				ans[cnt].s1=1,ans[cnt].s2=2;
				q1.pop_front();
				continue;
			}
			q1.push_back(a[i]);
		}
		printf("%lld\n",cnt);
		for(int i=1;i<=cnt;++i){
			if(ans[i].op==1)printf("1 %lld\n",ans[i].s1);
			else printf("2 %lld %lld\n",ans[i].s1,ans[i].s2);
		}
	}
}

signed main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	t=read();
	if(t%10==1)work1();
	else if(t%10==2)work3();
	else if(t%10==3||t%10==4)work2();
	else work1();
	return 0;
}
/*
1
3 8 4
1 2 3 4 1 2 3 4
*/
