#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=1;--i)
#define N 400005
using namespace std;

int read(){
	int x=0,w=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*w;
}

int T,n,m,k,tot;
int a[4000005],nxt[N],to[4000005];
int ed[N],tp[N],pos[N];
struct node{int opt,x,y;}ans[N];
deque<int> q[N];

void init(){
	tot=0;
	rep(i,1,k) nxt[i]=0,ed[i]=tp[i]=pos[i]=0; 
	rep(i,1,m) to[i]=0;
	rep(i,1,k) q[i].clear();
}
void del1(int x){
	int t=q[x].front();
	tp[a[t]]=ed[a[t]]=0; q[x].pop_front();
	if(!q[x].empty()){
		t=q[x].front();
		tp[a[t]]=1; 
		if(q[x].size()==1) ed[a[t]]=1;
	}
}
void del2(int x){
	int t=q[x].back();
	ed[a[t]]=tp[a[t]]=0; q[x].pop_back();
	if(!q[x].empty()){
		t=q[x].back();
		ed[a[t]]=1;
		if(q[x].size()==1) tp[a[t]]=1;
	}
}
void add(int x,int k){
	ans[++tot].opt=1; ans[tot].x=x;
	pos[a[k]]=x;
	if(!q[x].empty()){
		int t=q[x].front();
		tp[a[t]]=0; tp[a[k]]=1; q[x].push_front(k);
	}
	else{
		tp[a[k]]=ed[a[k]]=1;
		q[x].push_front(k);
	}
}
void solve1(){
	rep(i,1,m) {
		a[i]=read(); 
		if(nxt[a[i]]) to[nxt[a[i]]]=i,to[i]=nxt[a[i]],nxt[a[i]]=0;
		else nxt[a[i]]=i;
	}
	rep(i,1,m){
		//if(T==0&&i<=35) if(!q[4].empty()) cout<<i<<" "<<q[4].front()<<endl;
		if(to[i]<i){
			if(tp[a[i]]){
				ans[++tot].opt=1,ans[tot].x=pos[a[i]];
				del1(pos[a[i]]);
			}
			else if(ed[a[i]]){
				rep(j,1,n) if(q[j].empty()){
					ans[++tot].opt=1; ans[tot].x=j;
					ans[++tot].opt=2; ans[tot].x=pos[a[i]],ans[tot].y=j;
					del2(pos[a[i]]); break;
				}
			}
//			else cout<<i<<" "<<a[i]<<endl;
		}
		else{
			int maxn=0,p=1;
			rep(j,1,n) if(!q[j].empty()){
				int w=to[q[j].front()];
				if(w>maxn) maxn=w,p=j;
			}
//			if(i==19) cout<<maxn<<" "<<p<<endl;
			if(maxn<to[i]){
//				if(i==19) puts("!!!");
				int flag=0;
				rep(j,1,n) if(q[j].empty()) {
						flag=1;add(j,i);break;
				} 
				if(!flag) add(p,i);
			}
			else add(p,i);
		}
	}
//	rep(i,1,n) if(q[i].size()) puts("!!!");
	printf("%d\n",tot);
	rep(i,1,tot){
		if(ans[i].opt==1) printf("1 %d\n",ans[i].x);
		else printf("2 %d %d\n",ans[i].x,ans[i].y);
	}
}

void solve(){
	n=read(); m=read(); k=read(); init();
	solve1();
}

signed main(){
	
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	
	T=read();
	while(T--) solve();
	return 0;
}
/*
1
4 14 7
1 2 3 4 5 6 7
2 3 4 5 6 7 1

*/



