#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<set>
#include<map>
#include<string>
#include<cstring>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=200+10;
const int M=2e6+10;
struct Node{
	int type;
	int s;
	int s1,s2;
};
vector<Node> vc;
deque<int> q[N];
int p[M];
int n,m,k;
int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d%d",&n,&m,&k);
		memset(p,0,sizeof(p));
		vc.clear();
		for(int i=1;i<=n;i++)
		{
			q[i].clear();
		}
		for(int i=1;i<=m;i++)
		{
			scanf("%d",&p[i]);
		}
		int op=0;
		if(k==2*n-2)
		{
			for(int i=1;i<=m;i++)
			{
				int num=(p[i]+1)/2;
				if(q[num].empty())
				{
					op++;
					q[num].push_front(p[i]);
					Node tmp;
					tmp.type=1;
					tmp.s=num;
					vc.push_back(tmp);		
					continue;						
				}
				if(q[num].front()==p[i])
				{
					op++;
					q[num].pop_front();
					Node tmp;
					tmp.type=1;
					tmp.s=num;
					vc.push_back(tmp);		
					continue;			
				}
				if(q[num].back()==p[i])
				{	
					op+=2;
					q[num].pop_back();
					Node tmp;
					tmp.type=1;
					tmp.s=n;
					vc.push_back(tmp);
					Node tmp2;
					tmp2.type=2;
					tmp2.s1=num;
					tmp2.s2=n;
					vc.push_back(tmp2);						
				}
				else
				{
					op++;
					q[num].push_front(p[i]);
					Node tmp;
					tmp.type=1;
					tmp.s=num;
					vc.push_back(tmp);		
					continue;					
				}
			}
		}
		else if(n==2)
		{
			for(int i=1;i<=m;i++)
			{
				if(!q[1].empty() && q[1].front()==p[i])
				{
					op++;
					q[1].pop_front();
					Node tmp;
					tmp.type=1;
					tmp.s=1;
					vc.push_back(tmp);
					continue;
				}
				if(!q[2].empty() && q[2].front()==p[i])
				{
					op++;
					q[2].pop_front();
					Node tmp;
					tmp.type=1;
					tmp.s=2;
					vc.push_back(tmp);
					continue;
				}
				if(q[1].empty() && q[2].empty())
				{
					op++;
					q[1].push_back(p[i]);
					Node tmp;
					tmp.type=1;
					tmp.s=1;
					vc.push_back(tmp);
					continue;
				}
				if(q[1].empty() && q[2].back()==p[i])
				{
					q[1].push_back(p[i]);
					op++;
					Node tmp;
					tmp.type=1;
					tmp.s=1;
					vc.push_back(tmp);
				}
				if(q[2].empty() && q[1].back()==p[i])
				{
					q[2].push_back(p[i]);
					op++;
					Node tmp;
					tmp.type=1;
					tmp.s=2;
					vc.push_back(tmp);
				}
				if(!q[1].empty() && !q[2].empty() && (q[1].back() == q[2].back()) )
				{
					q[1].pop_back();
					q[2].pop_back();
					op++;
					Node tmp;
					tmp.type=2;
					tmp.s1=1,tmp.s2=2;
					vc.push_back(tmp);
					continue;
				}
				op++;
				q[1].push_front(p[i]);
				Node tmp;
				tmp.type=1;
				tmp.s=1;
				vc.push_back(tmp); 
			} 
		}	
		else
		{
			for(int i=1;i<=m;i++)
			{
				bool flag=false;
				for(int j=1;j<=n;j++)
				{
					if(!q[j].empty() && q[j].front()==p[i])
					{
						op++;
						q[j].pop_front();
						Node tmp;
						tmp.type=1;
						tmp.s=j;
						vc.push_back(tmp);
						flag=true;
						break;						
					}
				}
				if(flag) continue;
				for(int j=1;j<=n;j++)
				{
					if(!q[j].empty()) continue;
					for(int k=1;k<=n;k++)
					{
						if(j==k) continue;
						if(q[k].empty()) continue;
						if(q[k].back()==p[i])
						{
							q[k].pop_back();
							op+=2;
							Node tmp;
							tmp.type=1;
							tmp.s=j;
							vc.push_back(tmp);
							Node tmp2;
							tmp2.type=2;
							tmp2.s1=j;
							tmp2.s2=k;
							vc.push_back(tmp2);
							flag=true;
							break;
						}	
					}
					if(flag) break;
				}
				if(flag) continue;
				int num=0,id=0;
				for(int j=1;j<=n;j++)
				{
					if(q[j].empty()) num++,id=j;
				}
				if(num>1)
				{
					op++;
					q[id].push_front(p[i]);
					Node tmp;
					tmp.type=1;
					tmp.s=id;
					vc.push_back(tmp); 					
				}
				else
				{
					for(int j=1;j<=n;j++)
					{
						if(!q[j].empty())
						{
							op++;
							q[j].push_front(p[i]);
							Node tmp;
							tmp.type=1;
							tmp.s=j;
							vc.push_back(tmp); 
							break;						
						}
					}
				}
			}
		}		
		printf("%d\n",op);
		for(int i=0;i<op;i++)
		{
			if(vc[i].type==1)
			{
				printf("1 %d\n",vc[i].s);
			}
			else printf("2 %d %d\n",vc[i].s1,vc[i].s2);
		} 
	}
}