#include<bits/stdc++.h>
using namespace std;
#define mkp make_pair
#define pii pair<int,int>
#define fi first
#define se second
const int N=2e6+5,M=305;
int a[N];
inline int read()
{
	char C=getchar();
	int ANS=0,F=1;
	while (C<'0'||C>'9')
	{
		if (C=='-') F=-1;
		C=getchar();
	}
	while (C>='0'&&C<='9')
	{
		ANS=ANS*10+(C-'0');
		C=getchar();
	}
	return ANS*F;
}
int n,m,k;
vector<int>c;
vector<pair<int,pii>>ans;
int g;
int p[N];
deque<int>st[M];

void work1(int l,int r)
{
	//cout << 111 << endl;
	ans.push_back(mkp(1,mkp(g,0)));
	for (int i=l+1;i<r;i++)
	{
		int u=a[i];
		if (p[a[i]]!=0)
		{
			if (p[u]>0) 
			{
				st[p[u]].pop_front();
				ans.push_back(mkp(1,mkp(p[u],0)));
				c.push_back(p[u]);
			}
			else
			{
				st[-p[u]].pop_back();
				ans.push_back(mkp(1,mkp(g,0)));
				ans.push_back(mkp(2,mkp(g,-p[u])));
				c.push_back(-p[u]);
				if (!st[-p[u]].empty()) p[st[-p[u]].front()]*=-1;
			}
			p[u]=0;
		}
		else if (c.size())
		{
			int v=c.back();
			if (st[v].empty()) 
			{
				ans.push_back(mkp(1,mkp(v,0)));
				p[u]=-v;
			}
			else
			{
				ans.push_back(mkp(1,mkp(v,0)));
				p[u]=v;
			}
			c.pop_back();
			st[v].push_front(u);
		}
		else assert(0);
	}
	ans.push_back(mkp(1,mkp(g,0)));
}

void add(int u)
{
	if (p[u])
	{
		if (p[u]>0) 
		{
			st[p[u]].pop_front();
			ans.push_back(mkp(1,mkp(p[u],0)));
			c.push_back(p[u]);
		}
		else
		{
			st[-p[u]].pop_back();
			ans.push_back(mkp(1,mkp(g,0)));
			ans.push_back(mkp(2,mkp(g,-p[u])));
			c.push_back(-p[u]);
			if (!st[-p[u]].empty()) p[st[-p[u]].front()]*=-1;
		}
		p[u]=0;
	}
	else if (c.size())
	{
		int v=c.back();
		if (st[v].empty()) 
		{
			ans.push_back(mkp(1,mkp(v,0)));
			p[u]=-v;
		}
		else
		{
			ans.push_back(mkp(1,mkp(v,0)));
			p[u]=v;
		}
		c.pop_back();
		st[v].push_front(u);
	}
}

void work2(int l,int r)
{
	int pos=-p[a[r]];
	int u=a[r],v=st[pos].front();
	int cnt=0;
	for (int i=l;i<=r;i++) if (a[i]==v) cnt++;
	if (cnt%2==0)
	{
		ans.push_back(mkp(1,mkp(pos,0)));
		for (int i=l+1;i<=r;i++)
		{
			if (a[i]==v) ans.push_back(mkp(1,mkp(pos,0)));
			else if (a[i]==u) 
			{
				if (p[u]>0) 
				{
					st[p[u]].pop_front();
					ans.push_back(mkp(1,mkp(p[u],0)));
					c.push_back(p[u]);
				}
				else
				{
					st[-p[u]].pop_back();
					ans.push_back(mkp(1,mkp(g,0)));
					ans.push_back(mkp(2,mkp(g,-p[u])));
					if (!st[-p[u]].empty()) p[st[-p[u]].front()]*=-1;
				}
				p[a[l]]=-p[u];
				p[u]=0;
				st[pos].push_front(a[l]);
			}
			else add(a[i]);
		}
	}
	else
	{
		ans.push_back(mkp(1,mkp(g,0)));
		for (int i=l+1;i<=r;i++)
		{
			if (a[i]==v) ans.push_back(mkp(1,mkp(pos,0)));
			else if (a[i]==u) ans.push_back(mkp(1,mkp(pos,0)));
			else add(a[i]);
		}
		c.push_back(g);
		st[g].push_front(a[l]);
		p[a[l]]=-g;
		g=pos;
		while (!st[pos].empty()) st[pos].pop_front();
	}
}

void work()
{
	n=read(),m=read(),k=read();
	for (int i=1;i<=m;i++) a[i]=read();
	g=n;
	c.clear(),ans.clear();
	for (int i=1;i<n;i++) c.push_back(i),c.push_back(i);
	for (int i=1;i<=n;i++) while (!st[i].empty()) st[i].pop_front();
	for (int i=1;i<=k;i++) p[i]=0;
	//return ;
	for (int i=1;i<=m;i++)
	{
//		cout << i << endl;
//		for (int j=1;j<=2;j++) cout << p[j] << " ";
//		cout << endl;
//		for (int j:c) cout << j << " ";
//		cout << endl;
		int u=a[i];
		if (p[u])
		{
			if (p[u]>0) 
			{
				st[p[u]].pop_front();
				ans.push_back(mkp(1,mkp(p[u],0)));
				c.push_back(p[u]);
			}
			else
			{
				st[-p[u]].pop_back();
				ans.push_back(mkp(1,mkp(g,0)));
				ans.push_back(mkp(2,mkp(g,-p[u])));
				c.push_back(-p[u]);
				if (!st[-p[u]].empty()) p[st[-p[u]].front()]*=-1;
			}
			p[u]=0;
		}
		else if (c.size())
		{
			int v=c.back();
			if (st[v].empty()) 
			{
				ans.push_back(mkp(1,mkp(v,0)));
				p[u]=-v;
			}
			else
			{
				ans.push_back(mkp(1,mkp(v,0)));
				p[u]=v;
			}
			c.pop_back();
			st[v].push_front(u);
		}
		else
		{
			int j=i+1;
			while (j<=m)
			{
				if (a[j]==u)
				{
					work1(i,j);
					i=j;
					break;
				}
				else if (p[a[j]]<0)
				{
					work2(i,j);
					i=j;
					break;
				}
				j++;
			}
		}
	}
	cout << ans.size() << "\n";
	for (auto i:ans)
	{
		if (i.fi==1)
		{
			printf("%d %d\n",1,i.se.fi);
		}
		else
		{
			printf("%d %d %d\n",2,i.se.fi,i.se.se);
		}
	}
}
int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T=read();
	while (T--) work();
	return 0;
}

/*
1
2 6 3
1 2 3 2 3 1
*/
