#include<bits/stdc++.h>
//#define int long long
#define Maxn (2000006)

using namespace std;

inline int read()
{
	int pos=1,num=0;
	char ch=getchar();
	while (!(ch>='0'&&ch<='9'))
	{
		if (ch=='-') pos=-1;
		ch=getchar();
	}
	while (ch>='0'&&ch<='9')
	{
		num=num*10+((int)ch-'0');
		ch=getchar();
	}
	return pos*num;
}

inline void write(int x)
{
	if (x<0)
	{
		putchar('-');
		write(-x);
		return;
	}
	if (x>=10) write(x/10);
	putchar((char)(x%10)+'0');
	return;
}
inline void writeln(int x)
{
	write(x);
	puts("");
	return;
}
inline void writesp(int x)
{
	write(x);
	putchar(' ');
	return;
}
int a[Maxn],id[Maxn],p[Maxn],F[Maxn],vis[Maxn],now[Maxn],ans[Maxn],FF[Maxn],zqq1[Maxn],zqq2[Maxn];
signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T=read();
	while (T--)
	{
		int n=read(),m=read();
		int k=read(),op=0;
		for (int i=1;i<=m;i++) a[i]=read();
		bool fg=0;
//		for (int i=1;i<=m;i++)
//		{
//			pre[i]=head[a[i]];
//			head[a[i]]=i;
//		}
		for (int i=1;i<=n;i++)
			id[i]=i,id[i+n]=i;
		//Fi--zhan 01
		//visi--weizhi 0 1 2
		//nowi--i weizhi 
		for (int i=1;i<=m;i++)
		{
			int x=a[i];
//			writeln(vis[x]);
			if (vis[x]==2) 
			{
				ans[i]=now[x];
				op++,FF[now[x]]=0,vis[x]=0,F[now[x]]=0,now[x]=0;
				fg=0;
			}else {
			if (vis[x]==1)
			{
//				writeln(i);
				op++;
				int tong1=now[x],tong2=now[x]+n;
				int x2=F[tong2];
				if (fg==0)
				{
					ans[i]=now[x];
					if (!F[2*n])
					{
						for (int asd=2*n;asd>=tong2+1;asd--)
						{	
							ans[FF[asd-1]]=asd;
							F[asd]=F[asd-1];
							now[F[asd]]=asd;
							ans[FF[asd]]=asd+1;
						}
						}else{
						for (int asd=n+1;asd<=tong2-1;asd++)
							{	
								ans[FF[asd+1]]=asd;
								F[asd]=F[asd+1];
								now[F[asd]]=asd;
							}
						}
					vis[x]=0;now[x]=0;
					F[tong1]=0;fg=1;
				}else{
					op++;
					zqq1[i]=ans[i-1];
					p[i]=1;
					zqq2[i]=now[x];
					F[tong1]=F[tong2];
					F[tong2]=0;
					vis[x]=0;now[x]=0;
					fg=0;
				}
				
			}else{
				int tong=1;
				op++;
				for (;tong<=2*n;tong++)
					if (!F[tong]) break; 
				if (tong>=1&&tong<=n)
				{
					FF[tong]=i;F[tong]=x;vis[x]=2;now[x]=tong;
				}else {
					vis[F[tong-n]]=1;
					FF[tong]=i;F[tong]=x;vis[x]=1;now[x]=tong;
				}
				ans[i]=tong;
				fg=0;
			}}
			
		}
		for (int i=1;i<=op;i++)
			if (!p[i])writesp(1),writeln(id[ans[i]]);else writesp(2),writesp(zqq1[i]),writeln(zqq2[i]);
	}
	return 0;
}

/*
1
4 14 7
1 2 3 4 5 6 7 1 2 3 4 5 6 7
*/