#include <bits/stdc++.h>
using namespace std;
int T,n,m,k;
int ceshiid;
int a[2000005];
int number[2000005];
int stackup[500],stackdown[500];
vector<pair<int,int>> oper,emp;
int toto=0;
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	cin>>T;
	ceshiid=T;
	while(T--){
		cin>>n>>m>>k;
		oper=emp;
		toto=0;
		for(int i=1;i<=m;i++)scanf("%d",&a[i]);
		for(int i=1;i<=m;i++){
			number[i]=0;
		}
		for(int i=1;i<=n;i++){
			stackup[i]=0;
			stackdown[i]=0;
		}
		if(ceshiid==1002||(n==2&&k==3)){
			stack<int> aa,bb;
			for(int i=1;i<=m;i++){
				if(!aa.empty()&&aa.top()==a[i]){
					aa.pop();
					toto++;
					oper.push_back(make_pair(1,0));
				}else if(!bb.empty()&&bb.top()==a[i]){
					bb.pop();
					toto++;
					oper.push_back(make_pair(2,0));
				}else if(aa.empty()){
					aa.push(a[i]);
					toto++;
					oper.push_back(make_pair(1,0));
				}else if(bb.empty()){
					bb.push(a[i]);
					toto++;
					oper.push_back(make_pair(2,0));
				}else{
					if(aa.top()==a[i+1]){
						bb.push(a[i]);
						toto++;
					oper.push_back(make_pair(2,0));
					}else if(bb.top()==a[i+1]){
						aa.push(a[i]);
						toto++;
					oper.push_back(make_pair(1,0));
					}else{
						aa.push(a[i]);
						toto++;
					oper.push_back(make_pair(1,0));
					}
				}
			}
			cout<<toto<<endl;
			for(int i=0;i<oper.size();i++){
				if(oper[i].second==0){
					printf("1 %d\n",oper[i].first);
				}else{
					printf("2 %d %d\n",oper[i].first,oper[i].second);
				}
			}
			continue;
		}
		if(k==2*n-2||ceshiid==1001){
			for(int i=1;i<=m;i++){
				if(number[a[i]]==0){
					bool hasgot=false;
					for(int j=2;j<=n;j++){
						if(stackdown[j]==0){
							toto++;
							oper.push_back(make_pair(j,0));
							stackdown[j]=a[i];
							number[a[i]]=j;
							hasgot=true;
							break;
						}
						else if(stackup[j]==0){
							toto++;
							oper.push_back(make_pair(j,0));
							stackup[j]=a[i];
							number[a[i]]=n+j;
							hasgot=true;
							break;
						}
					}
				}else{
					if(number[a[i]]>n){
						oper.push_back(make_pair(number[a[i]]-n,0));
						toto++;
						stackup[number[a[i]]-n]=0;
						number[a[i]]=0; 
					}else{
						oper.push_back(make_pair(1,0));
						toto++;
						oper.push_back(make_pair(1,number[a[i]]));
						toto++;
						stackdown[number[a[i]]]=stackup[number[a[i]]];
						number[stackup[number[a[i]]]]-=n;
						stackup[number[a[i]]]=0;
						number[a[i]]=0;
					}
				}
			}
			cout<<toto<<endl;
			for(int i=0;i<oper.size();i++){
				if(oper[i].second==0){
					printf("1 %d\n",oper[i].first);
				}else{
					printf("2 %d %d\n",oper[i].first,oper[i].second);
				}
			}
			continue;
		}
	}
}
