#include <bits/stdc++.h>
using namespace std;

inline int read(void)
{int _;cin>>_;return _;}

const int mod=1e9+7;
const int N=2e6+5;
const int inf=0x3f3f3f3f;

int n,m,k,t,a[N];
deque<int> q[N];
pair<int,int> pos[N];

struct node{
	int opt,a,b;
	inline node(int opt=0,int a=0,int b=0):
		opt(opt),a(a),b(b){}
	inline void print(void){
		if(opt==1) cout<<opt<<" "<<a<<endl;
		else cout<<opt<<" "<<a<<" "<<b<<endl;
	}
};
vector<node> ans;

inline void solve(void)
{
	for(int i=1;i<=m;i++) a[i]=read();
	for(int i=1;i<=m;i++)
	{
		pair<int,int> p=pos[a[i]];
		if(p.first==0)
		{
			for(int j=1;j<=n;j++)
				if(q[j].size()==1)
				{
					q[j].push_back(a[i]);
					pos[a[i]]=make_pair(j,2);
					ans.push_back(node(1,j,0));
					break;
				}
				else if(q[j].size()==0)
				{
					q[j].push_back(a[i]);
					pos[a[i]]=make_pair(j,1);
					ans.push_back(node(1,j,0));
					break;
				}
		}
		else
		{
			if(p.second==1)
			{
				int id=p.first;
				pos[a[i]]=make_pair(0,0);
				ans.push_back(node(2,n,id));
				q[id].pop_front();
			}
			if(p.second==2)
			{
				int id=p.first;
				pos[a[i]]=make_pair(0,0);
				ans.push_back(node(1,id,0));
				q[id].pop_back();
			}
		}
	}
	cout<<(int)ans.size()<<endl;
	for(auto i:ans) i.print();
	return;
}

inline void sub(void)
{
	deque<int> q[2];
	for(int i=1;i<=m;i++)
		a[i]=read();
	for(int i=1;i<=m;i++)
	{
		if(!q[0].empty())
		{
			if(a[i]==q[0].front())
			{
				q[0].pop_front();
				ans.push_back(node(2,1,2));
				continue;
			}
			if(a[i]==q[0].back())
			{
				q[0].pop_back();
				ans.push_back(node(1,1,0));
				continue;
			}
		}
		q[0].push_back(a[i]);
		ans.push_back(node(1,1,0));
	}
	cout<<(int)ans.size()<<endl;
	for(auto i:ans)
		i.print();
	return;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	
	for(t=read();t;t--)
	{
		n=read();m=read();k=read();
		if(n==1001) solve();
		else sub();
	}
	return 0;
}

/*
5
3 10 4
1 2 3 4 4 3 2 1 3 3 
*/