#include<bits/stdc++.h>
#define elif else if
#define pc putchar(' ')
#define pn puts("")
#define rep(i,l,r) for(int i=(l),j=(r);i<=j;++i)
#define per(i,r,l) for(int i=(r),j=(l);i>=j;--i)
//#define int long long
#define N 305
#define A 0x3f3f3f3f
using namespace std;
int read(){int ret=0,b=1,c=getchar();while(!isdigit(c))b=c=='-'?-1:1,c=getchar();while(isdigit(c))ret=ret*10+c-'0',c=getchar();return ret*b;}
void wr(int x){if(x<0)putchar('-'),x=-x;if(x>9)wr(x/10);putchar(x%10+'0');return;}
void wrc(int x){wr(x),pc;return;}
void wrn(int x){wr(x),pn;return;}
int Min(int x,int y){return x<=y?x:y;}
int Max(int x,int y){return x>=y?x:y;}
void Swap(int &x,int &y){x^=y,y^=x,x^=y;return;}
int n,m,k,a[N];
queue<int> q[N],sp,ans;
stack<int> s[N];
void init()
{
	return;
}
signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int x,y,z,T=read();
	while(T--)
	{
		n=read(),m=read(),k=read(),init();
		rep(i,1,k)
			while(q[i].size())
				q[i].pop();
		while(sp.size())
			sp.pop();
		rep(i,1,n)
			sp.push(i);
		rep(i,1,m)
			a[i]=read();
		rep(i,1,m)
		{
			if(!q[a[i]].size())
			{
				x=sp.front(),sp.pop();
				ans.push(x);
				s[x].push(a[i]);
				q[a[i]].push(x);
			}
			else
			{
				x=q[a[i]].front(),q[a[i]].pop();
				ans.push(x);
				if(s[x].size())
				{
					z=s[x].top();
					q[z].push(x);
				}
				else
					sp.push(x);
			}
		}
		wrn(ans.size());
		while(ans.size())
			printf("1 %d\n",ans.front()),ans.pop();
	}
	fclose(stdin),fclose(stdout);return 0;
}
