#include<algorithm>
#include<cassert>
#include<cstdio>
#include<cstring>
#include<vector>
#define ff first
#define ss second
const int M = 2000010,N = 310;
const int Optkind[7] = {1,1,1,1,1,2,1};
const int Optpos[6] = {1,2,2,1,1,2};
using std::make_pair;
int T,n,m,k,a[M],bottom[N],top[N],pos;
int optpos[M],ans[M*2][2],anscnt;
void solve1()
{
	while (T--)
	{
		scanf("%d%d%d",&n,&m,&k);
		memset(bottom,0,sizeof(int)*(n+10));
		memset(top,0,sizeof(int)*(n+10));
		anscnt = 0;
		for (int i = 1;i <= m;++i)
			scanf("%d",&a[i]);
		for (int i = 1;i <= m;++i)
		{
			pos = (a[i]+1)/2;
			if (!bottom[pos])
				ans[++anscnt][0] = 1,ans[anscnt][1] = pos,bottom[pos] = a[i];
			else if (bottom[pos] == a[i])
			{
				ans[++anscnt][0] = 1,ans[anscnt][1] = n;
				ans[++anscnt][0] = 2,ans[anscnt][1] = pos;
				if (top[pos])
					bottom[pos] = top[pos],top[pos] = 0;
			}
			else
				ans[++anscnt][0] = 1,ans[anscnt][1] = pos,top[pos] = a[i];
		}
		printf("%d\n",anscnt);
		for (int i = 1;i <= anscnt;++i)
			if (ans[i][0] == 1)
				printf("1 %d\n",ans[i][1]);
			else
				printf("2 %d %d\n",ans[i][1],n);
	}
}

std::vector<std::pair<int,int>> vec1[M],vec2[M];

void dfs1(std::vector<std::pair<int,int>> x,int &pos,int y);
void dfs2(std::vector<std::pair<int,int>> x,int &pos,int y);

void dfs1(std::vector<std::pair<int,int>> x,int &pos,int y)
{
	for (int i = x.size()-1;~i;--i)
		if (x[i].ss == -1)
		{
			optpos[x[i].ff] = 3-optpos[y];
			if (vec1[x[i].ff].size())
				dfs1(vec1[x[i].ff],pos,x[i].ff);
			++pos,ans[pos][0] = 1,ans[pos][1] = optpos[x[i].ff];
			if (vec2[x[i].ff].size())
				dfs2(vec2[x[i].ff],pos,x[i].ff);
		}
		else
		{
			optpos[x[i].ff] = optpos[x[i].ss] = 1;
			if (vec1[x[i].ff].size())
				dfs1(vec1[x[i].ff],pos,x[i].ff);
			++pos,ans[pos][0] = ans[pos][1] = 1;
			if (vec2[x[i].ff].size())
				dfs2(vec2[x[i].ff],pos,x[i].ff);
			if (vec1[x[i].ss].size())
				dfs1(vec1[x[i].ss],pos,x[i].ss);
			++pos,ans[pos][0] = ans[pos][1] = 1;
			if (vec2[x[i].ss].size())
				dfs2(vec2[x[i].ss],pos,x[i].ss);
		}
}

void dfs2(std::vector<std::pair<int,int>> x,int &pos,int y)
{
	for (int i = 0;i < x.size();++i)
		if (x[i].ss == -1)
		{
			optpos[x[i].ff] = 3-optpos[y];
			if (vec1[x[i].ff].size())
				dfs1(vec1[x[i].ff],pos,x[i].ff);
			++pos,ans[pos][0] = 1,ans[pos][1] = optpos[x[i].ff];
			if (vec2[x[i].ff].size())
				dfs2(vec2[x[i].ff],pos,x[i].ff);
		}
		else
		{
			optpos[x[i].ff] = optpos[x[i].ss] = 1;
			if (vec1[x[i].ff].size())
				dfs1(vec1[x[i].ff],pos,x[i].ff);
			++pos,ans[pos][0] = ans[pos][1] = 1;
			if (vec2[x[i].ff].size())
				dfs2(vec2[x[i].ff],pos,x[i].ff);
			if (vec1[x[i].ss].size())
				dfs1(vec1[x[i].ss],pos,x[i].ss);
			++pos,ans[pos][0] = ans[pos][1] = 1;
			if (vec2[x[i].ss].size())
				dfs2(vec2[x[i].ss],pos,x[i].ss);
		}
}

int pre[M],next[M],p1,p2;

void solve2()
{
	int u,pos;
	while (T--)
	{
		scanf("%d%d%d",&n,&m,&k),next[0] = 1,vec2[0].clear();
		for (int i = 1;i <= m;++i)
			scanf("%d",&a[i]),vec1[i].clear(),vec2[i].clear(),
			pre[i] = i-1,next[i] = i+1;
		for (int i = 2;i <= m;++i)
			if (a[i] == a[pre[i]])
			{
				u = pre[pre[i]],next[u] = next[i],pre[next[i]] = u;
				vec2[u].push_back(make_pair(pre[i],i));
			}
			else if (a[i] == a[pre[pre[i]]])
			{
				u = pre[pre[i]],next[pre[u]] = pre[i],pre[pre[i]] = pre[u],
				next[pre[i]] = next[i],pre[next[i]] = pre[i];
				vec1[pre[i]].push_back(make_pair(u,-1));
				vec2[pre[i]].push_back(make_pair(i,-1));
			}
		p1 = p2 = 0,pos = 0;
		if (vec2[0].size())
			dfs2(vec2[0],pos,0);
		for (int i = next[0];i <= m;i = next[i])
		{
			optpos[i] = Optpos[p2];
			if (vec1[i].size())
				dfs1(vec1[i],pos,i);
			ans[++pos][0] = Optkind[p1],p1 = (p1+1)%7;
			ans[pos][1] = Optpos[p2],p2 = (p2+1)%10;
			if (Optkind[p1] == 2)
				++pos,ans[pos][0] = 2,p1 = (p1+1)%7;
			if (vec2[i].size())
				dfs2(vec2[i],pos,i);
		}
		printf("%d\n",pos);
		for (int i = 1;i <= pos;++i)
			if (ans[i][0] == 1)
				printf("1 %d\n",ans[i][1]);
			else
				puts("2 1 2");
	}
}
int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	scanf("%d",&T);
	if (T == 1001)
	{
		solve1();
		return 0;
	}
	if (T == 1002)
	{
		solve2();
		return 0;
	}
	assert(1 == 2);
	while (T--)
	{
		scanf("%d%d%d",&n,&m,&k);
		for (int i = 1;i <= m;++i)
			scanf("%d",&a[i]);
	}
	return 0;
}