
#include<bits/stdc++.h>
//#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define vi vector<int>
#define vpi vector<pii>
using namespace std;

inline void ckmin(int &a,int b){a=(a<b?a:b);}
inline void ckmax(int &a,int b){a=(a>b?a:b);}
inline int read()
{
	int f=1,num=0;char ch=getchar();
	while(!(ch=='-'||(ch<='9'&&ch>='0')))ch=getchar();
	if (ch=='-')f=-1,ch=getchar();
	while(ch<='9'&&ch>='0')num=num*10+ch-'0',ch=getchar();
	return num*f;
}

const int M=610;
const int N=2e6+10;
int n,a[N],m,k,sz[M],st[M][10],vis[M],tmp[M];
vector<pair<int,pii>>ans;

void check()
{
	for (int i=1;i<=n;i++)sz[i]=0;
	int now=0;
	for (auto x:ans)
	{
		if (x.x==1)
		{
			int pos=x.y.x;now++;
			assert(pos<=n),assert(pos>=1);
			st[pos][++sz[pos]]=a[now];
			if (sz[pos]>=2&&st[pos][sz[pos]]==st[pos][sz[pos]-1])sz[pos]-=2;
//			cerr<<"p "<<pos<<'\n';
		}
		else
		{
			int u=x.y.x,v=x.y.y;
			if (st[u][1]!=st[v][1])cerr<<"Error:"<<u<<' '<<v<<' '<<now<<'\n';
			assert(u!=v),assert(min(u,v)>=1),assert(max(u,v)<=n);
			assert(sz[u]!=0),assert(sz[v]!=0),assert(st[u][1]==st[v][1]);
			sz[u]--,sz[v]--;
			for (int i=1;i<=sz[u];i++)st[u][i]=st[u][i+1];
			for (int i=1;i<=sz[v];i++)st[v][i]=st[v][i+1];
//			cerr<<"ers "<<u<<' '<<v<<'\n';
		}
		/*
		for (int i=1;i<=n;i++)
		{
			cerr<<sz[i]<<":\n";
			for (int j=1;j<=sz[i];j++)cerr<<st[i][j]<<(j==sz[i]?'\n':' ');
		}*/
	}
	assert(now==m);
	for (int i=1;i<=n;i++)assert(sz[i]==0);
//	cerr<<"OK\n";
}

void solve()
{
	n=read(),m=read(),k=read();ans.clear();
	set<int>s1,s2;
	for (int i=1;i<=n;i++)sz[i]=0,s1.insert(i);
	for (int i=1;i<=k;i++)vis[i]=0;
	for (int i=1;i<=m;i++)a[i]=read();
	int cnt=0;
	for (int i=1;i<=m;i++)
	{
		if (!vis[a[i]])
		{
			if (cnt==2*n-2)
			{
				int pos=-1;
				for (int j=i+1;j<=m;j++)
					if (a[j]==a[i]||st[vis[a[j]]][1]==a[j])
						{pos=j;break;}
				assert(pos!=-1);
				if (a[pos]==a[i])
				{
					int p=*s1.begin();
					ans.pb(mp(1,mp(p,0)));
					for (int j=i+1;j<pos;j++)
						ans.pb(mp(1,mp(vis[a[j]],0))),tmp[vis[a[j]]]^=1;
					for (int j=i+1;j<pos;j++)
						if (tmp[vis[a[j]]])tmp[vis[a[j]]]=0,sz[vis[a[j]]]=1,s2.insert(vis[a[j]]),vis[a[j]]=0,cnt--,
					ans.pb(mp(1,mp(p,0)));
				}
				else
				{
					int p=vis[a[pos]],y=st[p][2],cnt=0;
					for (int j=i+1;j<pos;j++)
						if (a[j]==y)cnt^=1;
					if (cnt==0)
					{
						ans.pb(mp(1,mp(p,0)));
						for (int j=i+1;j<pos;j++)
							ans.pb(mp(1,mp(vis[a[j]],0))),tmp[vis[a[j]]]^=1;
						ans.pb(mp(1,mp(*s1.begin(),0)));
						ans.pb(mp(2,mp(p,*s1.begin())));
						vis[st[p][1]]=0,vis[a[i]]=p;
						st[p][1]=y,st[p][2]=a[i];
						for (int j=i+1;j<pos;j++)
							if (tmp[vis[a[j]]])
								tmp[vis[a[j]]]=0,sz[vis[a[j]]]=1,s2.insert(vis[a[j]]),vis[a[j]]=0,cnt--;
					}
					else
					{
						int x=*s1.begin();
						ans.pb(mp(1,mp(x,0)));s1.erase(x);sz[x]=1,st[x][1]=a[i],s2.insert(x);
						for (int j=i+1;j<=pos;j++)
							ans.pb(mp(1,mp(vis[a[j]],0))),tmp[vis[a[j]]]^=1;
						for (int j=i+1;j<=pos;j++)
							if (tmp[vis[a[j]]])
								tmp[vis[a[j]]]=0,sz[vis[a[j]]]=1,s2.insert(vis[a[j]]),vis[a[j]]=0,cnt--;
						s1.insert(p),sz[p]=0,vis[y]=vis[a[pos]]=0,cnt--;
					}
				}
				i=pos;
			}
			else
			{
				if (s2.size())
				{
					int x=*s2.begin();
					sz[x]=2,st[x][2]=a[i];
					ans.pb(mp(1,mp(x,0)));
					s2.erase(x);vis[a[i]]=x;
				}
				else if (s1.size())
				{
					int x=*s1.begin();
					ans.pb(mp(1,mp(x,0)));
					sz[x]=1;st[x][1]=a[i];
					s1.erase(x),s2.insert(x);
					vis[a[i]]=x;
				}
				cnt++;
			}
		}
		else
		{
			cnt--;int p=vis[a[i]];
			if (st[p][1]==a[i])
			{
				int x=*s1.begin();
				ans.pb(mp(1,mp(x,0)));
				ans.pb(mp(2,mp(x,p)));
				st[p][1]=st[p][2],
				sz[p]--;
				if (sz[p]==0)s1.insert(p),s2.erase(p);
				else s2.insert(p);
			}
			else
			{
				ans.pb(mp(1,mp(p,0)));
				sz[p]--;
				if (sz[p]==0)s1.insert(p),s2.erase(p);
				else s2.insert(p);
			}
			vis[a[i]]=0;
		}
	}
	cout<<ans.size()<<'\n';
	for (auto x:ans)
		if (x.x==1)printf("1 %d\n",x.y.x);
		else printf("2 %d %d\n",x.y.x,x.y.y);
	check();
}

signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T=read();
	while(T--)solve(),cerr<<"OK"<<T<<'\n';
	return 0;
}
