#include<bits/stdc++.h>
#define int long long
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rep(i,a,b) for(int i=a;i>=b;i--)
#define p(x) printf("%lld ",(x))
#define P() puts("")
using namespace std;


inline int read()
{
	char c=getchar();int x=0;bool f=0;
	while(!isdigit(c)) f^=!(c^45),c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;
	return x;
}

inline int diread()
{
	char c=getchar();int x=0;
	while(!isdigit(c)) c=getchar();
	x=(c^48);
	return x;
}

const int maxn=1050;

int T,n,m,k,a[maxn];
int f[maxn][maxn];
int vis[maxn];

inline void solve1()
{
	//For(i,1,n)
	
	return ;
}
inline void solve2()
{
	
	while(T--)
	{
		n=read();m=read();k=read();
		For(i,1,m)
		{
			a[i]=read();
			vis[a[i]]=0;
		}
		
		//p(1LL);P();
		
		For(i,1,m)
		{
			if(!vis[a[i]])
			{
				For(j,1,n-1)
				{
					if(f[j][2]==0)
					{
						if(f[j][1]==0)
							f[j][1]=a[i];
						else
							f[j][2]=a[i];
						vis[a[i]]=j;
						p(1LL);p(j);P();
						break;
					}
				}
			}
			else
			{
				int pos=vis[a[i]];
				if(f[pos][1]==a[i])
				{
					f[pos][1]=f[pos][2];
					f[pos][2]=0;
					vis[a[i]]=0;
					p(1LL);p(n);P();
					p(2LL);p(pos);p(n);P();
				}
			}
		}
	}
}

signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	/*if(T==3) solve1();
	else */solve2();
	return 0;
}
