#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,x,y,z) for(long long i=x;i<=y;i+=z)
#define fd(i,x,y,z) for(long long i=x;i>=y;i-=z)
ll T;
ll n,m,k;
ll xg=0;
ll a[2000005];
ll ma[605];
ll nt[2000005];
ll tp,opt[4000005],l[4000005],r[4000005];
ll kx=0;
deque<ll> q2[305];
struct Node{
	ll id,nxt; 
};
bool operator <(Node x,Node y){
	return x.nxt>y.nxt;
}	
priority_queue<Node> q1;
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	scanf("%lld",&T);
	while(T--){
		scanf("%lld%lld%lld",&n,&m,&k);
		kx=n;
		xg=0;
		f(i,1,m,1){
			scanf("%lld",&a[i]);
			if(!ma[a[i]]){
				ma[a[i]]=i;
			}
			else{
				nt[ma[a[i]]]=i;
				ma[a[i]]=0;
			}
		}
//		f(i,1,m,1){
//			printf("%lld ",nt[i]);
//		}
//		printf("\n");
		f(i,1,m,1){
			//printf("%lld\n",kx);
			if(nt[i]){
				q1.push(Node{
					a[i],nt[i]
				});
				bool flag=false;
				f(j,1,n,1){
					if(j==kx){
						continue;
					}
					if(q2[j].size()<=1){
						opt[++tp]=1;
						l[tp]=j;
						q2[j].push_back(i);
						flag=true;
						break;
					}
				}
				if(!flag){
					bool ff=false;
					
					f(j,1,n,1){
						if(j==kx){
							continue;
						}
						if(nt[q2[j].back()]>nt[i]||nt[q2[j].back()]>nt[q2[j].front()]){
							opt[++tp]=1;
							l[tp]=j;
							q2[j].push_back(i);
							ff=true;
							break;
						}
					}
					if(!ff){
						opt[++tp]=1;
						l[tp]=kx;
						q2[kx].push_back(i);
						kx=0;
					}
				}
			}
			else{
				ll xx=q1.top().id;
				f(j,1,n,1){
					if(q2[j].size()){
						if(a[q2[j].back()]==xx){
							opt[++tp]=1;
							l[tp]=j;
							q2[j].pop_back();
							xg++;
							if(!kx){
								if(q2[j].size()==0){
									kx=j;
								}
							}
							break;
						}
						if(a[q2[j].front()]==xx&&kx){
							opt[++tp]=1;
							l[tp]=kx;
							opt[++tp]=2;
							l[tp]=j;
							r[tp]=kx;
							q2[j].pop_front();
							xg++;
							break;
						}
					}
				}
				q1.pop();
			}
		}
		//printf("%lld\n",xg);
		printf("%lld\n",tp);
		f(i,1,tp,1){
			printf("%lld ",opt[i]);
			if(opt[i]==1){
				printf("%lld\n",l[i]);
			}
			else{
				printf("%lld %lld\n",l[i],r[i]);
			}
			opt[i]=l[i]=r[i]=0;
		}
		tp=0;
		f(i,1,m,1){
			nt[i]=0;
		}
		f(i,1,k,1){
			ma[i]=0;
		}
		f(i,1,n,1){
//			if(q2[i].size()){
//				printf("XUN\n");
//			}
			q2[i].clear();
		}
		while(!q1.empty()){
			q1.pop();
		}
	}
	return 0;
}
/*
1
2 4 2
1 2 1 2

1
3 10 5
1 2 3 4 5 2 3 4 5 1

NOIP G.
*/

