#include <bits/stdc++.h>
#define rep(i, l, r) for(int i=l, _=r; i<=_; ++i)
typedef long long ll;
inline int read() {
	int res=0; char ch; bool k=1;
	while(!isdigit(ch=getchar())) k=ch^'-';
	do res=res*10+(ch^48); while(isdigit(ch=getchar()));
	return k? res: -res;
}
const int mM=2e6+9, mN=2e3+9;
bool Mbe;
int n, m, k, a[mM];
int col[mN], sta[mN][2];

int top, not2[mN], emp;

int tot, opt[mM*2][2];
//int err_cnt1=0;
inline void modify1(int s) {
//	++err_cnt1;
	++tot, opt[tot][0]=s, opt[tot][1]=0;
}
inline void modify2(int s1, int s2) {
	++tot, opt[tot][0]=s1, opt[tot][1]=s2;
}

inline bool check(int i) {
	int c=col[a[i]];
	if(c>0) {
		modify1(c);
		sta[c][1]=0, not2[++top]=c;
		col[a[i]]=0;
	} else if(c<0) {
		c=-c;
//		printf("emp = %d, c = %d\n", emp, c);
		modify1(emp), modify2(c, emp);
		if(sta[c][1]) {
			sta[c][0]=sta[c][1], sta[c][1]=0, not2[++top]=c;
			col[sta[c][0]]=-c;
		} else {
			sta[c][0]=0;
		}
		col[a[i]]=0;
	} else if(top) {
		c=not2[top];
		modify1(c);
		if(sta[c][0]) {
			sta[c][1]=a[i], --top;
			col[a[i]]=c;
		} else {
			sta[c][0]=a[i];
			col[a[i]]=-c;
		}
	} else {
		return 0;
	}
	return 1;
}

int T, vis[mN];
inline void solve(int i, int j, int c) {
	rep(l, i, j) {
		modify1(col[a[l]]);
	}
	rep(l, i, j) {
		if(col[a[l]] && vis[a[l]]==T) {
			sta[col[a[l]]][1]=0;
			if(col[a[l]]!=c) {
				not2[++top]=col[a[l]];
			}
			col[a[l]]=0;
		}
	}
}

bool Men;
int main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
//	std::cerr<<"memory: "<<(&Mbe-&Men>>20)<<" MB\n";

	int T_T=read();
	while(T_T--) {
//		err_cnt1=0;
		memset(col, 0, sizeof col);
		memset(sta, 0, sizeof sta);
		tot=0, memset(opt, 0, sizeof opt);

		n=read(), m=read(), k=read();
		rep(i, 1, n-1) not2[i]=i;
		top=n-1, emp=n;

		rep(i, 1, m) a[i]=read();
		for(int i=1; i<=m; ) {
			if(check(i)) {
//				std::cerr<<"mei zi bi!\n";
				++i;
			} else {	// I spend 46min /fad/ll/tuu
//				std::cerr<<"zi bi le!\n";
				++T;
				int cntup=0, j=i+1;
				for(; j<=m; ++j) {
					if(a[j]==a[i]) {
						break;
					} else if(vis[a[j]]!=T) {
						if(col[a[j]]<0) {
							break;
						} else {
							++cntup, vis[a[j]]=T;
							if(cntup==n-1) break;
						}
					} else {
						--cntup, vis[a[j]]=-T;
					}
				}
				assert(j<=m);
				if(col[a[j]]<0) {
//					std::cerr<<"case 0\n";
					int c=-col[a[j]];
					if(vis[sta[c][1]]!=T) {
//						std::cerr<<"case 0.0\n";
						modify1(c);
						solve(i+1, j-1, emp);
						modify1(emp), modify2(c, emp);
						col[sta[c][0]]=0;
						sta[c][0]=sta[c][1], sta[c][1]=a[i];
						col[sta[c][0]]=-c, col[a[i]]=c;
					} else {
						modify1(emp);
						solve(i+1, j-1, c);
						modify1(c);
						sta[c][0]=0;
						col[a[j]]=0;
						sta[emp][0]=a[i], not2[++top]=emp;
						col[a[i]]=-emp;
						emp=c;
					}
					i=j+1;
				} else if(a[j]==a[i]) {
//					std::cerr<<"case 1\n";
					modify1(emp);
					solve(i+1, j-1, emp);
					modify1(emp);
					i=j+1;
				} else {
//					std::cerr<<"case 2\n";
					modify1(emp);
					solve(i+1, j, emp);
					sta[emp][0]=a[i]/*, not2[++top]=emp*/;
					col[a[i]]=-emp;
					i=j+1;
					for(j=i; j<=m && col[a[j]]>=0; ) ++j;
					emp=-col[a[j]];
					top=0;
					rep(l, 1, n) if(l!=emp) not2[++top]=/*emp*/l;
					rep(l, i, j-1) {
						int c=col[a[l]];
						if(c>0) {
							modify1(c);
							sta[c][1]=0, not2[++top]=c;
							col[a[l]]=0;
						} else {
							c=not2[top];
							modify1(c);
							if(sta[c][0]) {
								sta[c][1]=a[/*i*/l], --top;
								col[a[l]]=c;
							} else {
								sta[c][0]=a[l];
								col[a[l]]=-c;
							}
						}
					}
					modify1(emp);
					sta[emp][0]=0;
					col[a[j]]=0;
					i=j+1;
				}
//				rep(i, 1, k) printf("col[%d] = %d\n", i, col[i]);
//				rep(i, 1, n) printf("sta[%d] = %d, %d\n", i, sta[i][0], sta[i][1]);
//				rep(i, 1, top) printf("not2[%d] = %d\n", i, not2[i]);
//				printf("emp = %d\n", emp);
//				std::cerr<<"i = "<<i<<"\n";
			}
//			assert(err_cnt1==i-1);
		}

		printf("%d\n", tot);
		rep(i, 1, tot) {
			if(!opt[i][1]) {
				printf("1 %d\n", opt[i][0]);
			} else {
				printf("2 %d %d\n", opt[i][0], opt[i][1]);
			}
		}
	}
	return 0;
}
/*
40+58+54
*/