#include<bits/stdc++.h>
#define forr(i,l,r) for(int i=l;i<=r;i++)
#define ffor(i,r,l) for(int i=r;i>=l;i--)
#define int long long
using namespace std;
const int N=2e6+10,M=305;
int a[N],c[M][710],cnt[M];
signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t,n,m,k,ans=0,j;
	cin>>t;
	while(t--)
	{
		ans=0;
		cin>>n>>m>>k;
		memset(cnt,0,sizeof(cnt));
		memset(c,0,sizeof(c));
		forr(i,1,m)
		{
			cin>>a[i];
		}
		if(k==2*n-2)
		{
			forr(i,1,m)
			{
				j=(a[i]+1)/2;
				if(c[j][1]==a[i])
				{
					ans++;
				}
				else if(c[j][cnt[j]]==a[i])
				{
				}
				else
				{
					cnt[j]++;
					c[j][cnt[j]]=a[i];
				}
			}
			cout<<ans+m<<endl;
			memset(cnt,0,sizeof(cnt));
			memset(c,0,sizeof(c));
			forr(i,1,m)
			{
				j=(a[i]+1)/2;
				if(c[j][1]==a[i])
				{
					cout<<1<<" "<<n<<endl;
					cout<<2<<" "<<j<<" "<<n<<endl;
				}
				else if(c[j][cnt[j]]==a[i])
				{
					cout<<1<<" "<<j<<endl;
				}
				else
				{
					cout<<1<<" "<<j<<endl;
					cnt[j]++;
					c[j][cnt[j]]=a[i];
				}
			}
		}
		else
		{
			cout<<m<<endl;
			forr(i,1,m)
			{
				cout<<1<<" "<<1<<endl;
			}
		}
	}
}