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

const int M=2e6+5;
const int N=1e3+5;

int a[M];

map<pair<int,int>,int> mp;
#define pii(x,y) make_pair(x,y)
deque<int>q[N];

struct node{int pp,a,b;}ot[N];

int oq[M],oh,ota,vis[N];

int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);	

	int T;cin>>T;
	while(T--){
		int n,m,k;
		cin>>n>>m>>k;
		for(int i=1;i<=m;++i)cin>>a[i];
		
		/*init*/
		for(int i=1;i<=n;++i)
			for(int j=1;j<=k;++j)
				mp[pii(i,j)]=-1;
		int cnt=0;
		for(int i=1;i<=n;++i)while(!q[i].empty())q[i].pop_back();
		oh=0;ota=0;
		for(int i=1;i<=n;++i)vis[i]=0;
		
		/*start*/	
		for(int i=1;i<=m;++i){
			int x=a[i],op=1;
			// same: front and back
			for(int j=1;j<=n;++j)if(!q[j].empty()){
				if(q[j].back()==x){
					op=0;
					q[j].pop_back();mp[pii(j,x)]=-1;
					cnt++;ot[cnt]=(node){1,j,0};
					break;
				}
				if(q[j].front()==x){
					op=0;
					int flag=0;
					for(int k=1;k<=n;++k)if(q[k].empty()){
						q[j].pop_front();mp[pii(j,x)]=-1;
						cnt++;ot[cnt]=(node){1,k,0};
						cnt++;ot[cnt]=(node){2,j,k};
						flag=1;
						break;
					}
					if(flag)break;
					else{
						int flag2=0;
						for(int k=1;k<=n;++k)if(mp[pii(k,x)]==-1){
							q[k].push_back(x);mp[pii(k,x)]=1;
							cnt++;ot[cnt]=(node){1,k,0};
							flag2=1;
							break;
						}
						if(!flag2){
							q[1].push_back(x),mp[pii(1,x)]=1;
							cnt++;ot[cnt]=(node){1,1,0};
						}	
						break;
					}
				}
			}
			//no same
			if(op){
				for(int j=1;j<=n;++j)if(mp[pii(j,x)]==-1){
					q[j].push_back(x);mp[pii(j,x)]=1;
					cnt++;ot[cnt]=(node){1,j,0};
					break;
				}
			}
		}

		oh=1;for(int i=1;i<=n;++i)if(!q[i].empty())oq[++ota]=i;
		
		while(oh<=ota){
			while(vis[oq[oh]]==1)oh++;
			int u=oq[oh];
			for(int i=u+1;i<=ota;++i){
				int flag=1;int v=oq[i];
				while(q[u].front()==q[v].front()){
					flag=0;
					q[u].pop_front();q[v].pop_front();
					cnt++;ot[cnt]=(node){2,u,v};
				}
				if(q[u].empty())vis[u]=1;
				if(q[v].empty())vis[v]=1;
				if(flag==0)break;
			}
		}
		
		/*Output*/
		printf("%d\n",cnt);
		for(int i=1;i<=cnt;++i){
			printf("%d ",ot[i].pp);
			if(ot[i].pp==1)printf("%d\n",ot[i].a);
			else printf("%d %d\n",ot[i].a,ot[i].b);
		}
	}
}

/*
3 10 5
1 2 3 4 5 2 3 4 5 1
*/


