#include<bits/stdc++.h>
using namespace std;
int t;
int n,m,k;
const int N=4e6+10;
int a[N];
//int la[N];
//int p[1010];
//int ne[1010];
int cp[1010];
bool seqq[1010];
int con[N];
bool vis[N];
int pas[1010];
int d[1010];
int st[1010];
int tot=0;
int con2[N];
queue<int>sq;
queue<int>nq;
int pc;
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	scanf("%d",&t);
	while(t){
		tot=0;
		while(!sq.empty())sq.pop();
		while(!nq.empty())nq.pop();
		t--;
		scanf("%d%d%d",&n,&m,&k);
		for(int i=1;i<=m;i++)scanf("%d",&a[i]);
		for(int i=1;i<=m;i++){
			if(a[i]==a[i-1]&&vis[i-1]==0){
				vis[i]=vis[i-1]=1;
				continue;
			}
//			la[i]=p[a[i]];
//			if(la[i]!=0)ne[la[i]]=i;
//			p[a[i]]=i;
		}
		bool gh=1;//empty
		for(int i=2;i<=n;i++){
			sq.push(i);nq.push(i);
		}
		for(int i=1;i<=k;i++)seqq[i]=0;
		for(int i=1;i<=m;i++){
			if(vis[i]){
				tot+=1;
				continue;
			}
			if(gh==1){
				if(seqq[a[i]]){
					if(cp[a[i]]==1){
						tot+=2;
						con[i]=1;
						con2[i]=st[a[i]];
						if(pas[st[a[i]]]){
							cp[a[pas[st[a[i]]]]]=1;
							nq.push(st[a[i]]);
							pas[st[a[i]]]=0;
							d[st[a[i]]]=pas[st[a[i]]];
						}
						else{
							d[st[a[i]]]=0;
							sq.push(st[a[i]]);
						}
					}else{
						tot+=1;
						con[i]=2;
						con2[i]=st[a[i]];
						pas[st[a[i]]]=0;
						nq.push(st[a[i]]);
					}
					seqq[a[i]]=0;
				}else if(!sq.empty()){
					tot+=1;
					st[a[i]]=sq.front();
					seqq[a[i]]=1;
					sq.pop();
					cp[a[i]]=1;
					con[i]=2;
					con2[i]=st[a[i]];
					d[st[a[i]]]=i;
				}else if(!nq.empty()){
					tot+=1;
					st[a[i]]=nq.front();
					nq.pop();
					seqq[a[i]]=1;
					con[i]=2;
					con2[i]=st[a[i]];
					cp[a[i]]=2;
					pas[st[a[i]]]=i;
				}else{
					gh=0;
					pc=i;
				}
			}else{
				if(a[i]==a[pc]){
					tot+=2;
					gh=1;
					vis[pc]=vis[i]=1;
				}
				else if(cp[a[i]]==1){
					if(pas[st[a[i]]]){
						gh=1;
						tot+=3;
						con[pc]=2;
						con2[pc]=st[a[i]];
						con[i]=1;
						con2[i]=st[a[i]];
						nq.push(st[a[i]]);
						cp[a[pas[st[a[i]]]]]=1;
						d[st[a[i]]]=pas[st[a[i]]];
						pas[st[a[i]]]=pc;
						cp[a[pc]]=2;
					}else{
						tot+=1;
						con[i]=2;
						con2[i]=st[a[i]];
						sq.push(st[a[i]]);
						d[st[a[i]]]=0;
					}
				}else{
					tot+=1;
					con[i]=2;
					con2[i]=st[a[i]];
					nq.push(st[a[i]]);
					pas[st[a[i]]]=0;
				}
				seqq[a[i]]=0;
			}
		}
		printf("%d\n",tot);
		for(int i=1;i<=m;i++){
			if(vis[i]){
				printf("1 1\n");
			}else if(con[i]==1){
				printf("1 1\n2 1 %d\n",con2[i]);
			}else{
				printf("1 %d\n",con2[i]);
			}
		}
	}
	return 0;
}
