#include<bits/stdc++.h>
using namespace std;
inline long long read()
{
	long long s=0,k=1;
	char r=getchar();
	while(!isdigit(r))
	{
		k=(r=='-')?-1:1;
		r=getchar();
	}
	while(isdigit(r))
	{
		s=s*10+(r-'0');
		r=getchar();
	}
	return s*k;
}
#define d read()
#define ll long long
#define Maxn 10010
#define Size 1010
#define pb push_back
#define mp make_pair
#define fi first
#define se second
bool vis[Size];
vector<pair<int,int> >todo;
vector<int>st[Size];
void solve()
{
	ll n=d,m=d,k=d;
	if(k==2*n-2)
	{
		for(int i=0;i<m;i++)
		{
			ll x=d;
			if(vis[x])
			{
				if(st[(x>n-1)?(x-n+1):x].back()==x)
					todo.pb(mp((x>n-1)?(x-n+1):x,0)),
					st[(x>n-1)?(x-n+1):x].pop_back();
				else
					todo.pb(mp(n,0)),todo.pb(mp(x,n)),
					st[(x>n-1)?(x-n+1):x].erase(st[(x>n-1)?(x-n+1):x].begin());
				vis[x]=0;
			}
			else
			{
				todo.pb(mp(((x>n-1)?(x-n+1):x),0));
				vis[x]=1;
				st[(x>n-1)?(x-n+1):x].pb(x);
			}
		}
	}
	else
	{
		for(int i=0;i<m;i++) d;
	}
	printf("%lld\n",todo.size());
	for(auto now:todo)
		if(now.se==0) printf("1 %d\n",now.fi);
		else printf("2 %d %d\n",now.fi,now.se);
	todo.clear();
}
int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	ll t=d;
	while(t--) solve();
}
