#include<bits/stdc++.h>
using namespace std;
int T,n,m,k;
int a[2000005];
vector<int> st[305];
int low[305],top[305];
inline int havetop(int x)
{
	for(register int i=1;i<=n;i++)
	if(st[i].size())
		if(st[i][top[i]-1]==x) return i;
	return 0; 
}
inline int havelow(int x)
{
	int flg=0;
	for(register int i=1;i<=n;i++)
	if(top[i]==low[i]) 
	{
		flg=1;
		break;
	}
	if(!flg) return 0;
	for(register int i=1;i<=n;i++)
	if(st[i].size()&&top[i]!=low[i])
		if(st[i][low[i]]==x) return i;
	return 0;
}
int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>T;
	while(T--)
	{
		cin>>n>>m>>k;
		for(register int i=1;i<=n;i++) st[i].clear();
		memset(top,0,sizeof(top));
		memset(low,0,sizeof(low));
		for(register int i=1;i<=m;i++) cin>>a[i];
		if(k==2*n-2)
		{
			int op=0;
			for(register int i=1;i<=m;i++)
			{
				op++;
				int t=havetop(a[i]),s=havelow(a[i]);
				if(t) top[t]--;
				else if(s) low[s]++,op++;
				else
				{
					int minn=1e9,pos=0;
					for(register int i=1;i<=n;i++)
					if(minn>top[i]-low[i])
					{
						minn=top[i]-low[i];
						pos=i;
					}
					st[pos].push_back(a[i]),top[pos]++;
				}
			}
			cout<<op<<endl;
			for(register int i=1;i<=n;i++) st[i].clear();
			memset(top,0,sizeof(top));
			memset(low,0,sizeof(low));
			for(register int i=1;i<=m;i++)
			{
				int t=havetop(a[i]),s=havelow(a[i]);
				if(t) 
				{
					top[t]--;
					cout<<1<<' '<<t<<endl;
				}
				else if(s) 
				{
					int flg=0;
					for(register int i=1;i<=n;i++)
					if(top[i]==low[i]) 
					{
						flg=i;
						break;
					}
					low[s]++;
					cout<<1<<' '<<flg<<endl<<2<<' '<<s<<' '<<flg<<endl;
				}
				else
				{
					int minn=1e9,pos=0;
					for(register int i=1;i<=n;i++)
					if(minn>top[i]-low[i])
					{
						minn=top[i]-low[i];
						pos=i;
					}
					st[pos].push_back(a[i]),top[pos]++;
					cout<<1<<' '<<pos<<endl;
				}
			}
		}
		else if(n==2)
		{
			int op=0;
			int i=1;
			while(i<=m)
			{
				op++;
				int t=havetop(a[i]),s=havelow(a[i]);
				if(t) 
				{
					top[t]--;
				//	cout<<1<<' '<<t<<endl;
				}
				else if(s) 
				{
					int flg=0;
					for(register int i=1;i<=n;i++)
					if(top[i]==low[i]) 
					{
						flg=i;
						break;
					}
					low[s]++;
					op++;
				//	cout<<1<<' '<<flg<<endl<<2<<' '<<s<<' '<<flg<<endl;
				}
				else
				{
					if(a[i]==a[i+1]) 
					{
						op++,i++;
					//	cout<<"1 1"<<endl<<"1 1"<<endl;
					}
					else if(a[i]==a[i+2])
					{
						op++;
						int u=havetop(a[i+1]),v=havelow(a[i+1]);
						if(u) 
						{
							top[u]--;
						//	cout<<1<<' '<<3-u<<endl<<1<<' '<<u<<endl<<1<<' '<<3-u<<endl;
						}
						else if(v) 
						{
							low[v]++,op++;
							int flg=0;
							for(register int i=1;i<=n;i++)
							if(top[i]==low[i])
							{
								flg=i;
								break;
							}
						//	cout<<1<<' '<<3-flg<<endl<<1<<' '<<flg<<endl<<2<<' '<<v<<' '<<flg<<endl<<1<<' '<<3-flg<<endl;
						}
						else 
						{
							if(top[1]-low[1]>top[2]-low[2]) 
							{
								st[1].push_back(a[i+1]),top[1]++;
							//	cout<<1<<' '<<2<<endl<<1<<' '<<1<<endl<<1<<' '<<2<<endl;
							}
							else 
							{
								st[2].push_back(a[i+1]),top[2]++;
							//	cout<<1<<' '<<1<<endl<<1<<' '<<2<<endl<<1<<' '<<1<<endl;
							}
						}
						op++;
						i+=2;
					}
					else if(a[i]==a[i+3])
					{
						op++;
						int u=havetop(a[i+1]),v=havelow(a[i+1]);
						if(u) 
						{
							top[u]--;
							//cout<<1<<' '<<3-u<<endl<<1<<' '<<u<<endl;
						}
						else if(v) 
						{
							low[v]++,op++;
							int flg=0;
							for(register int i=1;i<=n;i++)
							if(top[i]==low[i])
							{
								flg=i;
								break;
							}
							//cout<<1<<' '<<3-flg<<endl<<1<<' '<<flg<<endl<<2<<' '<<v<<' '<<flg<<endl;
						}
						else 
						{
							if(top[1]-low[1]>top[2]-low[2]) 
							{
								st[1].push_back(a[i+1]),top[1]++;
								//cout<<1<<' '<<2<<endl<<1<<' '<<1<<endl;
							}
							else 
							{
								st[2].push_back(a[i+1]),top[2]++;
								//cout<<1<<' '<<1<<endl<<1<<' '<<2<<endl;
							}
						}
						op++;
						u=havetop(a[i+2]),v=havelow(a[i+2]);
						if(u)
						{
							top[u]--;
							//cout<<1<<' '<<u<<endl<<1<<' '<<3-u<<endl;
						}
						else if(v)
						{
							low[v]++,op++;
							int flg=0;
							for(register int i=1;i<=n;i++)
							if(top[i]==low[i])
							{
								flg=i;
								break;
							}
							//cout<<1<<' '<<flg<<endl<<2<<' '<<v<<' '<<flg<<endl<<1<<' '<<3-flg<<endl;
						}
						else 
						{
							if(top[1]-low[1]>top[2]-low[2]) 
							{
								st[1].push_back(a[i+2]),top[1]++;
								//cout<<1<<' '<<1<<endl<<1<<' '<<2<<endl;
							}
							else 
							{
								st[2].push_back(a[i+2]),top[2]++;
								//cout<<1<<' '<<2<<endl<<1<<' '<<1<<endl;
							}
						}
						op++;
						i+=3;
					}
				}
				i++;
			}
			cout<<op<<endl;
			for(register int i=1;i<=n;i++) st[i].clear();
			memset(top,0,sizeof(top));
			memset(low,0,sizeof(low));
			i=1;
			while(i<=m)
			{
				op++;
				int t=havetop(a[i]),s=havelow(a[i]);
				if(t) 
				{
					top[t]--;
					cout<<1<<' '<<t<<endl;
				}
				else if(s) 
				{
					int flg=0;
					for(register int i=1;i<=n;i++)
					if(top[i]==low[i]) 
					{
						flg=i;
						break;
					}
					low[s]++;
					op++;
					cout<<1<<' '<<flg<<endl<<2<<' '<<s<<' '<<flg<<endl;
				}
				else
				{
					if(a[i]==a[i+1]) 
					{
						op++,i++;
						cout<<"1 1"<<endl<<"1 1"<<endl;
					}
					else if(a[i]==a[i+2])
					{
						op++;
						int u=havetop(a[i+1]),v=havelow(a[i+1]);
						if(u) 
						{
							top[u]--;
							cout<<1<<' '<<3-u<<endl<<1<<' '<<u<<endl<<1<<' '<<3-u<<endl;
						}
						else if(v) 
						{
							low[v]++,op++;
							int flg=0;
							for(register int i=1;i<=n;i++)
							if(top[i]==low[i])
							{
								flg=i;
								break;
							}
							cout<<1<<' '<<3-flg<<endl<<1<<' '<<flg<<endl<<2<<' '<<v<<' '<<flg<<endl<<1<<' '<<3-flg<<endl;
						}
						else 
						{
							if(top[1]-low[1]>top[2]-low[2]) 
							{
								st[1].push_back(a[i+1]),top[1]++;
								cout<<1<<' '<<2<<endl<<1<<' '<<1<<endl<<1<<' '<<2<<endl;
							}
							else 
							{
								st[2].push_back(a[i+1]),top[2]++;
								cout<<1<<' '<<1<<endl<<1<<' '<<2<<endl<<1<<' '<<1<<endl;
							}
						}
						op++;
						i+=2;
					}
					else if(a[i]==a[i+3])
					{
						op++;
						int u=havetop(a[i+1]),v=havelow(a[i+1]);
						if(u) 
						{
							top[u]--;
							cout<<1<<' '<<3-u<<endl<<1<<' '<<u<<endl;
						}
						else if(v) 
						{
							low[v]++,op++;
							int flg=0;
							for(register int i=1;i<=n;i++)
							if(top[i]==low[i])
							{
								flg=i;
								break;
							}
							cout<<1<<' '<<3-flg<<endl<<1<<' '<<flg<<endl<<2<<' '<<v<<' '<<flg<<endl;
						}
						else 
						{
							if(top[1]-low[1]>top[2]-low[2]) 
							{
								st[1].push_back(a[i+1]),top[1]++;
								cout<<1<<' '<<2<<endl<<1<<' '<<1<<endl;
							}
							else 
							{
								st[2].push_back(a[i+1]),top[2]++;
								cout<<1<<' '<<1<<endl<<1<<' '<<2<<endl;
							}
						}
						op++;
						u=havetop(a[i+2]),v=havelow(a[i+2]);
						if(u)
						{
							top[u]--;
							cout<<1<<' '<<u<<endl<<1<<' '<<3-u<<endl;
						}
						else if(v)
						{
							low[v]++,op++;
							int flg=0;
							for(register int i=1;i<=n;i++)
							if(top[i]==low[i])
							{
								flg=i;
								break;
							}
							cout<<1<<' '<<flg<<endl<<2<<' '<<v<<' '<<flg<<endl<<1<<' '<<3-flg<<endl;
						}
						else 
						{
							if(top[1]-low[1]>top[2]-low[2]) 
							{
								st[1].push_back(a[i+2]),top[1]++;
								cout<<1<<' '<<1<<endl<<1<<' '<<2<<endl;
							}
							else 
							{
								st[2].push_back(a[i+2]),top[2]++;
								cout<<1<<' '<<2<<endl<<1<<' '<<1<<endl;
							}
						}
						op++;
						i+=3;
					}
				}
				i++;
			}
		}
		else if(n==3)
		{
			
			continue;
		}
		else 
		{
			continue;
		}
	}
	return 0;
}
/*
1
2 4 2
1 2 1 2
*/
