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

int read(){
	int x=0,f=1; char ch=getchar();
	while (!isdigit(ch)){ if (ch=='-') f=-1; ch=getchar(); }
	while (isdigit(ch)){ x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}

bool ST;
const int N=2000005,M=605;

struct Node{
	int opt,v1,v2;
};

int n,m,k,a[N];
int Dn[N],Up[N];
deque <int> sta[M];
queue <int> ava;
vector <Node> ans;

void Delup(int x){
	ans.push_back((Node){1,x,0});
	Up[sta[x].back()]=0; sta[x].pop_back();
	if (sta[x].size()>=2) Up[sta[x].back()]=x;
	else ava.push(x);
}

void Deldn(int x,int y){
	ans.push_back((Node){2,x,y});
	Dn[sta[x].front()]=0,Dn[sta[y].front()]=0;
	sta[x].pop_front(); sta[y].pop_front();
	if (sta[x].size()) Dn[sta[x].front()]=x;
	else ava.push(x);
	if (sta[y].size()>=2) Dn[sta[y].front()]=y;
	else ava.push(y);
}

void Insup(int x,int y){
	ans.push_back((Node){1,x,0});
	if (sta[x].size()) Up[sta[x].back()]=0;
	sta[x].push_back(y);
	Up[y]=x;
	if (sta[x].size()==1) Dn[y]=x;
}

bool ED;

int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T=read();
	while (T--){
		ans.clear();
		n=read(),m=read(),k=read();
		for (int i=1;i<=m;++i) a[i]=read();
		
		for (int i=1;i<=n;++i)
			while (!sta[i].empty()) sta[i].pop_back();
		
		while (!ava.empty()) ava.pop();
		for (int i=1;i<=n;++i) ava.push(i);
		for (int i=1;i<=k;++i) Up[i]=0,Dn[i]=0;
		
		int i=1;
		while (i<=m){
			// printf("i=%d\n",i);
			if ((Up[a[i]]==0) && (Dn[a[i]]==0)){
				if (ava.size()==1){
					if (Up[a[i+1]]>0){
						int x=ava.front();
						Insup(x,a[i]);
						int rec=Up[a[i+1]];
						Delup(rec);
					}
					else {
						int x=ava.front(),y=Dn[a[i+1]];
						Insup(y,a[i]); Deldn(x,y);
					}
					i+=2;
				}
				else {
					int x=ava.front(); ava.pop();
					Insup(x,a[i]);
					++i;
				}
			}
			else if (Up[a[i]]>0) Delup(Up[a[i]]),++i;
			else {
				ans.push_back((Node){1,ava.front()});
				Deldn(ava.front(),Dn[a[i]]);
				++i;
			}
		}
		printf("%d\n",(signed)(ans.size()));
		for (auto it : ans)
			if (it.opt==1) printf("1 %d\n",it.v1);
			else printf("2 %d %d\n",it.v1,it.v2);
	}
	// cerr<<"MemoryUsed:"<<1.0*abs(&ST-&ED)/1024/1024<<endl;
	return 0;
}











