// Fresh Peach Heart Shower
#include <bits/stdc++.h>
#define pb push_back
#define MP std::make_pair
#define ALL(x) (x).begin(),(x).end()
#define mem(x,y) memset(x,y,sizeof(x))
#ifdef _LOCAL_
#define dprintf(x...) fprintf(stderr,x)
#else
#define dprintf(x...) 42
#endif
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
typedef std::vector<int > poly;
typedef std::pair<int,int > pii;
void setIn(std::string s){freopen(s.c_str(),"r",stdin);}
void setOut(std::string s){freopen(s.c_str(),"w",stdout);}
void setIO(std::string s){setIn(s+".in"),setOut(s+".out");}
template <class t> inline bool ckmin(t&x,t y){if(x>y)return x=y,1;return 0;}
template <class t> inline bool ckmax(t&x,t y){if(x<y)return x=y,1;return 0;}
inline int lowbit(int x){return x&(-x);}
#define fi first
#define se second
const int MaxN=605;
std::mt19937 rnd(time(0));
struct node
{
	int op,x,y;
}Q[4000050];
std::deque<pii > S[MaxN];
int a[2000050];
int in[1050],cnt[1050];
int n,m,K;
void work()
{
	std::cin>>n>>m>>K;
	rep(i,1,n)std::deque<pii >().swap(S[i]);
	rep(i,1,m)std::cin>>a[i];
	std::mem(in,0),std::mem(cnt,0);
	int incnt=0,q=0;
	int tim=0;
	rep(I,1,m)
	{
		int x=a[I];
		if(in[x])
		{
			int pos=0,tp=0,ed=0;
			rep(i,1,n)
			{
				if(!S[i].size())continue;
				if(S[i].back().fi==x)
				{
					pos=i;
					tp=1;
					break;
				}
				if(S[i].front().fi==x)
				{
					pos=i;
					ed=1;
					break;
				}
			}
//			dprintf("pos %d tp ed %d %d\n",pos,tp,ed);
			if(tp)
			{
				S[pos].pop_back();
				Q[++q]=(node){1,pos,0};
			}
			else
			{
				int fx=0,bs=0;
				rep(i,1,n)if(i!=pos)
				{
					if(!S[i].size())
					{
						fx=i;
						break;
					}
					if(S[i].size()==1u)
					{
//						dprintf("i %d\n",i);
						if(!bs||cnt[i]<cnt[bs])bs=i;
					}
				}
				if(fx)
				{
					S[pos].pop_front();
					Q[++q]=(node){1,fx,0};
					Q[++q]=(node){2,pos,fx};
				}
				else
				{
					bs=n;
//					assert(bs);
//					dprintf("bs %d\n",bs);
					cnt[bs]=++tim;
					int id1=S[bs].back().se;
					Q[id1].x=pos;
//					dprintf("id1 %d\n",id1);
					int id2=S[pos].front().se;
					Q[id2].x=bs;
					S[pos].front()=S[bs].back();
					if(S[pos].front().se>S[pos].back().se)
						std::swap(S[pos].front(),S[pos].back());
					S[bs].pop_back();
					Q[++q]=(node){1,bs,0};
				}
			}
			--incnt;
		}
		else
		{
			int it=0;
			rep(i,1,n)if(S[i].size()<=1u)
			{
				it=i;
				break;
			}
			Q[++q]=(node){1,it,0};
			S[it].push_back(MP(x,q));
			++incnt;
		}
		in[x]^=1;
/*		dprintf("I %d\n",I);
		rep(i,1,n)
		{
			for(auto j:S[i])dprintf("<%d>",j.fi);
			dprintf("\n");
		}*/
	}
	std::cout<<q<<'\n';
	rep(i,1,q)
	{
		if(Q[i].op==1)std::cout<<1<<' '<<Q[i].x<<'\n';
		else std::cout<<2<<' '<<Q[i].x<<' '<<Q[i].y<<'\n';
	}
}
signed main(void)
{
#ifndef _LOCAL_
	std::ios::sync_with_stdio(false),std::cin.tie(0);
#endif
	
	setIO("meow");

	int t;std::cin>>t;
	while(t--)work();
	return 0;
}


