#include<iostream>
#include<cstdio>
#include<vector>
#include<deque>
#include<set>
#define SZ(x) (int)(x.size())
using namespace std;
const int N=2e6+10;
const int M=1010;
int T;
int a[N];
int n,m,K;
int lst[N];
set <int> S[M];
deque <int> Q[M];
vector <int> v[M];
struct node{int tp,x,y;};
int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d%d",&n,&m,&K);
		for(int i=1;i<=m;i++) scanf("%d",&a[i]);
		for(int i=1;i<=n;i++) v[i].clear();
		for(int i=1;i<=K;i++) S[i].clear();
		if(K==n*2-2)
		{
			vector <node> ans;
			for(int i=1;i<=m;i++)
			{
				int x=(a[i]+1)/2;
				if(!SZ(v[x])) ans.push_back((node){1,x,0}),v[x].push_back(a[i]);
				else if(SZ(v[x])==1&&v[x][0]!=a[i])
					ans.push_back((node){1,x,0}),v[x].push_back(a[i]);
				else if(SZ(v[x])==1)
					ans.push_back((node){1,x,0}),v[x].pop_back();
				else
				{
					if(v[x][0]==a[i])
					{
						ans.push_back((node){1,n,0});
						ans.push_back((node){2,x,n});
						v[x].erase(v[x].begin());
					}
					else
					{
						ans.push_back((node){1,x,0});
						v[x].pop_back();
					}
				}
			}
			printf("%d\n",SZ(ans));
			for(node i:ans)
			{
				if(i.tp==1) printf("%d %d\n",i.tp,i.x);
				else printf("%d %d %d\n",i.tp,i.x,i.y);
			}
		}
		else
		{
			for(int i=1;i<=K;i++) lst[i]=0;
			for(int i=1;i<=n;i++) while(Q[i].size()) Q[i].pop_back();
			vector <node> ans;
			for(int i=1;i<=m;i++)
			{
				if(!SZ(S[a[i]]))
				{
					lst[a[i]]++;
					if(lst[a[i]]>=n) lst[a[i]]=1;
					int t=lst[a[i]];
					if(Q[t].size())
					{
						S[Q[t].front()].erase(t);
						S[Q[t].back()].insert(t);
						S[Q[t].back()].erase(t);
					}
					Q[t].push_back(a[i]);
					ans.push_back((node){1,t,0});
					S[Q[t].front()].insert(t),S[Q[t].back()].insert(t);
				}
				else
				{
					int t=*S[a[i]].begin();S[a[i]].erase(t);
					if(Q[t].back()==a[i]) ans.push_back((node){1,t,0}),Q[t].pop_back();
					else
					{
						ans.push_back((node){1,n,0});
						ans.push_back((node){2,t,n});
						Q[t].pop_front();
					}
					while(1)
					{
						if(!Q[t].size()) break;
						int x=0;
						for(int i=1;i<=n;i++)
							if(i!=t&&Q[i].size()&&Q[i].front()==Q[t].front())
								if(!x||Q[x].size()<Q[i].size()) x=i;
						if(!x) break;
						ans.push_back((node){2,t,x});
						S[Q[x].front()].erase(x);
						S[Q[x].back()].insert(x);
						S[Q[x].back()].erase(x);
						Q[t].pop_front(),Q[x].pop_front();
						if(Q[x].size()) S[Q[x].front()].insert(x),S[Q[x].back()].insert(x);
					}
					if(Q[t].size()) S[Q[t].front()].insert(t),S[Q[t].back()].insert(t);
				}
			}
			printf("%d\n",SZ(ans));
			for(node i:ans)
			{
				if(i.tp==1) printf("%d %d\n",i.tp,i.x);
				else printf("%d %d %d\n",i.tp,i.x,i.y);
			}
		}
	}
	return 0;
}
