#include<bits/stdc++.h>
#define int long long
using namespace std;
int Read(){
	char ch=getchar();
	int x=0;
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x;
}
queue<string> q;
int a[100005];
stack<int> stk[600];
signed main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T=Read();
	while(T--){
//		memset();
		int n=Read(),m=Read(),k=Read();
		printf("%lld\n",m);
		for(int i=1;i<=m;i++){
			a[i]=Read();
			bool flag=0;
			for(int j=1;j<=k;j++){
				if(stk[j].top()==a[i]){
					printf("1 %lld\n",j);
					stk[j].pop();
					flag=1;
				}
			}
			if(!flag){
				for(int j=1;j<=k;j++)
					if(!stk[j].size()){
						printf("1 %lld\n",j);
						stk[j].push(a[i]);
						flag=1;
					}
			}if(!flag){
				printf("1 1\n");
				stk[1].push(a[i]);
			}
		}
	}
	return 0;
}

