#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0)
#define lowbit(x) (x&(-x))
using namespace std;
const int N=610,M=2e6+10;
struct node
{
	int opt,x,y;
};
queue<pair<int,int> > q1,q2;
int n,m,k,a[M],bel[N],w[N][2],bel1[N],vis[N],q[N],cnt[N];
void solve()
{
	cin>>n>>m>>k;
	for (int i=1;i<=m;i++) cin>>a[i];
	int j=1,l=1,r=0; vector<node> ans;
	for (int i=1;i<=k;i++) bel[i]=0,w[i][0]=w[i][1]=0,bel1[i]=-1;
	for (int i=1;i<=n;i++) q1.push({i,0}),q2.push({i,1});
	for (int i=1;i<=m;i++)
	{
		while (r-l+1<2*n&&j<=m)
		{
			if (cnt[a[i]]==2) j++;
			else cnt[a[j]]++,q[++r]=a[j++];
		}
		if (!vis[a[i]])
		{
			pair<int,int> tmp;
			if (q1.size()>1||!q1.empty()&&bel1[q[r]]!=q1.front().first)
			{
				tmp=q1.front(); q1.pop();
				if (tmp.first==bel[q[r]]&&tmp.second==bel1[q[r]])
				{
					if (!q1.empty()) q1.push(tmp),tmp=q1.front();
					else q2.push(tmp),tmp=q2.front();
				}
			}
			else
			{
				tmp=q2.front(); q2.pop();
				if (tmp.first==bel[q[r]]) q2.push(tmp),tmp=q2.front();
			}
			bel[a[i]]=tmp.first; bel1[a[i]]=tmp.second; w[tmp.first][tmp.second]=1;
			ans.push_back({1,tmp.first,0}); vis[a[i]]=1;
		}
		else
		{
//			if (i==7) cout<<bel1[a[i]]<<' '<<w[3][1]<<'\n';
			if (bel1[a[i]]==0&&w[bel[a[i]]][1])
			{
				ans.push_back({1,q1.front().first,0});
				ans.push_back({2,bel[a[i]],q1.front().first});
				int tmp=w[bel[a[i]]][1]; w[bel[a[i]]][1]=0; w[bel[a[i]]][0]=tmp; bel1[tmp]=-1; vis[a[i]]=0;
				q1.push({bel[a[i]],0});
			}
			else
			{
				ans.push_back({1,bel[a[i]],0});
				w[bel[a[i]]][bel1[a[i]]]=0; vis[a[i]]=0;
				if (bel1[a[i]]==0) q1.push({bel[a[i]],0});
				else q2.push({bel1[a[i]],1});
			}
		}
		cnt[a[i]]--; l++;
	}
	cout<<ans.size()<<'\n';
	for (auto now:ans)
		if (now.opt==1) cout<<now.opt<<' '<<now.x<<'\n';
		else cout<<now.opt<<' '<<now.x<<' '<<now.y<<'\n';
//	cout<<'\n';
}
signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	IOS; int T; cin>>T;
	while (T--) solve();
}
