#include <bits/stdc++.h>
using namespace std;
const int N=300,M=6000000;

int n,m,k;
int pos[N+1<<1];
struct Move {
	int type,s,s2;
	Move(int a,int b,int c=-1) {type=a,s=b,s2=c;}
} ;
vector<Move> Ans;

deque<int> q[N+9];
vector<int> ch;

int a[M+9];
void solve() {
	scanf("%d%d%d",&n,&m,&k);
	Ans.clear();
	if (k==n*2-2) {
		ch.clear();
		for (int i=1;i<n;i++) ch.push_back(i);
		while (m--) {
			int t;
			scanf("%d",&t);
			if (!pos[t]) {
				int v=ch.back();
				Ans.push_back(Move(1,v));
				q[v].push_back(t),pos[t]=v;
				if (q[v].size()==2) ch.pop_back();
			} else if (q[pos[t]].back()==t) {
				Ans.push_back(Move(1,pos[t]));
				q[pos[t]].pop_back();
				if (q[pos[t]].size()==1) ch.push_back(pos[t]);
				pos[t]=0;
			} else {
				Ans.push_back(Move(1,n));
				Ans.push_back(Move(2,pos[t],n));
				q[pos[t]].pop_front();
				if (q[pos[t]].size()==1) ch.push_back(pos[t]);
				pos[t]=0;
			}
		}
	} else if (n==2) {
		for (int i=1;i<=m;i++) scanf("%d",a+i);
		int N1=1,N2=2;
		deque<int> p;
		p.clear();
		for (int i=1;i<=m;i++) {
			if (p.empty()) {
				Ans.push_back(Move(1,N1)),p.push_back(a[i]);
			} else if (a[i]==p.back()) {
				Ans.push_back(Move(1,N1));
				p.pop_back();
			} else if (a[i]==p.front()) {
				Ans.push_back(Move(1,N2)),Ans.push_back(Move(2,1,2));
				p.pop_front();
			} else if (p.size()==1) {
				Ans.push_back(Move(1,N1)),p.push_back(a[i]);
			} else {
				if (a[i+1]==p.front()) {
					Ans.push_back(Move(1,N1)),Ans.push_back(Move(1,N2)),Ans.push_back(Move(2,1,2));
					p.pop_front(),p.push_back(a[i]),i++;
				} else {
					int k=1,r;
					while (a[i+k+1]==a[i+1]) k++;
					r=k&1;
					if (r) {
						Ans.push_back(Move(1,N2));
						for (int j=2;j<=k;j+=2) Ans.push_back(Move(1,1)),Ans.push_back(Move(1,1));
						Ans.push_back(Move(1,N1));
						if (a[i+k+1]==a[i]) {
							Ans.push_back(Move(1,N2));
							p.pop_back();
						} else {
							Ans.push_back(Move(1,N1));
							p.pop_back(),p.pop_back(),p.push_back(a[i]),swap(N1,N2);
						}
					} else {
						Ans.push_back(Move(1,N1));
						for (int j=2;j<=k;j+=2) Ans.push_back(Move(1,1)),Ans.push_back(Move(1,1));
						if (a[i+k+1]==a[i]) {
							Ans.push_back(Move(1,N1));
						} else {
							Ans.push_back(Move(1,N2)),Ans.push_back(Move(2,1,2));
							p.pop_front(),p.push_back(a[i]);
						}
					}
					i+=k+1;
				}
			}
		}
	}
	printf("%d\n",Ans.size());
	for (auto ans:Ans)
		if (ans.type==1) printf("1 %d\n",ans.s);
		else if (ans.type==2) printf("2 %d %d\n",ans.s,ans.s2);
}

int main() {
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T;
	scanf("%d",&T);
	while (T--)
		solve();
	return 0;
}
