#include<bits/stdc++.h>
#define Cn const
#define CI Cn int&
#define N 300
#define M 2000000
using namespace std;
namespace FastIO
{
	#define FS 100000
	#define tc() (FA==FB&&(FB=(FA=FI)+fread(FI,1,FS,stdin),FA==FB)?EOF:*FA++)
	#define pc(c) (FC==FE&&(clear(),0),*FC++=c)
	int OT;char oc,FI[FS],FO[FS],OS[30],*FA=FI,*FB=FI,*FC=FO,*FE=FO+FS;
	void clear() {fwrite(FO,1,FC-FO,stdout),FC=FO;}
	void read(int& x) {x=0;while(!isdigit(oc=tc()));while(x=(x<<3)+(x<<1)+(oc&15),isdigit(oc=tc()));}
	void write(int x,char y) {while(OS[++OT]=x%10+48,x/=10);while(OT) pc(OS[OT--]);pc(y);}
}using namespace FastIO;
int n,m,k,a[M+5],nxt[M+5],p[2*N+5],G[2*N+5];deque<int> q[N+5];set<int> S0,S1,S2;
int ct;struct OP {int op,x,y;}ss[2*M+5];
void Push(int x,int v)
{
	ss[++ct]=(OP){1,x,0},G[v]=x,q[x].push_back(v);
	switch(q[x].size())
	{
		case 1:S0.erase(x),S1.insert(x);break;
		case 2:S1.erase(x),p[q[x].front()]<p[q[x].back()]&&(S2.insert(x),0);break;
		case 3:S2.erase(x);break;
	}
}
void PopChk(int x)
{
	switch(q[x].size())
	{
		case 0:S1.erase(x),S0.insert(x);break;
		case 1:S2.erase(x),S1.insert(x);break;
		case 2:p[q[x].front()]<p[q[x].back()]&&(S2.insert(x),0);break;
	}
}
int main()
{
	freopen("meow.in","r",stdin),freopen("meow.out","w",stdout);
	int Tt,i,x;read(Tt);while(Tt--)
	{
		for(read(n),read(m),read(k),i=1;i<=m;++i) read(a[i]);
		for(i=1;i<=k;++i) p[i]=G[i]=0;for(i=m;i;--i) nxt[i]=p[a[i]],p[a[i]]=i;
		for(S0.clear(),S1.clear(),S2.clear(),i=1;i<=n;++i) q[i].clear(),S0.insert(i);
		for(ct=0,i=1;i<=m;++i)
		{
			if(x=G[a[i]])
			{
				if(G[a[i]]=0,q[x].back()==a[i]) {ss[++ct]=(OP){1,x},q[x].pop_back(),PopChk(x);continue;}
				ss[++ct]=(OP){1,*S0.begin()},ss[++ct]=(OP){2,x,*S0.begin()},q[x].pop_front(),PopChk(x);continue;
			}
			if(p[a[i]]=nxt[i],S0.size()>1) Push(*S0.begin(),a[i]);else if(!S1.empty()) Push(*S1.begin(),a[i]);
			else if(!S2.empty()) Push(*S2.begin(),a[i]);else Push(*S0.begin(),a[i]);
		}
		for(write(ct,'\n'),i=1;i<=ct;++i) ss[i].op==1?(pc('1'),pc(' '),write(ss[i].x,'\n')):(pc('2'),pc(' '),write(ss[i].x,' '),write(ss[i].y,'\n'));
	}return clear(),0;
}
