#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define up(i,x,y) for(int i=x,i##E=y;i<=i##E;i++)
#define pu(i,x,y) for(int i=x,i##E=y;i>=i##E;i--)
#define up_(x) up(i,1,x)
#define mc cerr<<"qwq\n"
#define edl puts("")
#define pii pair<int,int>
#define mkp make_pair
#define ep push_back
#define vi vector<int>
#define upn up(i,1,n)
#define upm up(j,1,m)
#define fi first
#define se second
int n,m,k;
const int maxn=2e6+10;
int a[maxn];
deque<int>q[333];

signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T;
	srand(time(0));
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d%d",&n,&m,&k);
		up_(m)
		{
			scanf("%d",&a[i]);
		}
		
		if(k==n+n-2)
		{
			upn
			{
				while(q[i].size())q[i].pop_back();
			}
			vector<pair<int,pii>>v;
			up_(m)
			{
				int id=(a[i]+1)/2;
				if(q[id].size()==0)
				{
					v.ep(mkp(1,mkp(id,id)));
//					cout<<1<<" "<<id;edl;
					q[id].push_back(a[i]);
				}
				else
				{
					if(a[i]==q[id].back())
					{
						v.ep(mkp(1,mkp(id,id)));
//						cout<<1<<" "<<id;edl;
						q[id].pop_back();
					}
					else
					{
						if(a[i]==q[id].front())
						{
							v.ep(mkp(1,mkp(n,n)));
//							cout<<1<<" "<<n;edl;
							v.ep(mkp(2,mkp(id,n)));
//							cout<<2<<" "<<id<<" "<<n;edl;
							q[id].pop_front();
						}
						else
						{
							v.ep(mkp(1,mkp(id,id)));
//							cout<<1<<" "<<id;edl;
							q[id].push_back(a[i]);
						}
					}
				}
			}
			cout<<v.size();edl;
			for(auto x:v)
			{
				int p=x.fi,q=x.se.fi,r=x.se.se;
				if(p==1)
				{
					cout<<p<<" "<<q;edl;
				}
				else
				{
					cout<<p<<" "<<q<<" "<<r;edl;
				}
			}
			continue;
		}
		else
		{
			if(n==2&&k==3)
			{
				vector<pair<int,pii>>v;
				up(i,1,m)
				{
					if(a[i]==a[i+1])
					{
						v.ep(mkp(1,mkp(1,1)));
						v.ep(mkp(1,mkp(n,n)));
						i++;continue;
					}
					if(a[i]==1)
					{
						if(q[1].empty())
						{
							v.ep(mkp(1,mkp(1,1)));q[1].push_back(1);
						}
						else if(q[1].back()==1)
						{
							v.ep(mkp(1,mkp(1,1)));q[1].pop_back();
						}
						else
						{
							if(q[2].empty()&&q[1].front()==1)
							{
								v.ep(mkp(1,mkp(2,2)));v.ep(mkp(2,mkp(1,2)));
								q[1].pop_front();
							}
							else
							{
								v.ep(mkp(1,mkp(1,1)));q[1].push_back(1);
							}
						}
					}
					if(a[i]==2)
					{
						if(q[1].empty())
						{
							v.ep(mkp(1,mkp(1,1)));q[1].push_back(2);
						}
						else if(q[1].back()==2)
						{
							v.ep(mkp(1,mkp(1,1)));q[1].pop_back();
						}
						else
						{
							if(q[2].empty()&&q[1].front()==2)
							{
								v.ep(mkp(1,mkp(2,2)));v.ep(mkp(2,mkp(1,2)));
								q[1].pop_front();
							}
							else
							{
								v.ep(mkp(1,mkp(1,1)));q[1].push_back(2);
							}
						}
					}
					if(a[i]==3)
					{
						if(q[1].empty()&&q[2].empty())
						{
							q[1].push_back(3);v.ep(mkp(1,mkp(1,1)));
						}
						else
						{
							if(q[1].size()&&q[1].back()==3)
							{
								v.ep(mkp(1,mkp(1,1)));q[1].pop_back();
							}
							else if(q[2].size()&&q[2].back()==3)
							{
								v.ep(mkp(1,mkp(2,2)));q[2].pop_back();
							}
							else if(q[1].empty()&&q[2].front()==3)
							{
								v.ep(mkp(1,mkp(1,1)));v.ep(mkp(2,mkp(1,2)));
								q[2].pop_front();
							}
							else if(q[2].empty()&&q[1].front()==3)
							{
								v.ep(mkp(1,mkp(2,2)));v.ep(mkp(2,mkp(1,2)));
								q[1].pop_front();
							}
							else
							{
								if(q[1].back()==a[i+1])
								{
									v.ep(mkp(1,mkp(2,2)));q[2].push_back(3);
								}
								else
								{
									v.ep(mkp(1,mkp(1,1)));q[1].push_back(3);
								}
							}
						}
					}
				}
				cout<<v.size();edl;
				for(auto x:v)
				{
					int p=x.fi,q=x.se.fi,r=x.se.se;
					if(p==1)
					{
						cout<<p<<" "<<q;edl;
					}
					else
					{
						cout<<p<<" "<<q<<" "<<r;edl;
					}
				}
			}
		}
		
	}
	return 0;
}
/*
last chance，真的要折戟 T2 了吗？

*/