#include <bits/stdc++.h>
#define push Push
#define pop Pop
using namespace std;
const int maxn=4000005;
const int maxm=1005;
int n,m,P,l,r,lft,ans;
int a[maxn],pos[maxm],vis[maxm],sav[maxm],q[maxn],con[maxm];
bool prt;
inline int read(){
	char ch=getchar(); int ret=0,f=1;
	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
	while(isdigit(ch)){ret=ret*10+ch-'0';ch=getchar();}
	return ret*f;
}
inline int find(){
	for(int k=1;k<=(n<<1);k++)
	if(!(sav[k]||k==lft||k==lft+n))return k;
//	while(l<=r&&(sav[q[l]]||q[l]==lft||q[l]==lft+n)) l++;
	return -1;
}
inline void pop(int p){
	int x=sav[p];
	if(p<=n&&sav[p+n]&&pos[sav[p+n]]) sav[p]=sav[p+n],pos[sav[p]]=p,p+=n;
	q[++r]=p;
	sav[p]=0;
	pos[x]=0;
}
inline void push(int x,int p){
	if(p>n&&!sav[p-n]) p-=n;
	if(prt) printf("1 %d\n",(p-1)%n+1); else ans++;
	if(sav[p]){
		
		pop(p);
		return;
	}
	sav[p]=x;
	pos[x]=p;
}
void solve(){
	ans=0;
		lft=n;
		l=1; r=(n<<1);
		for(int k=1;k<=n;k++) q[k]=k;
		for(int k=1;k<=m;k++){
//			cout<<"k="<<k<<" "<<a[k]<<" "<<pos[a[k]]<<endl;
			int x=a[k];
			if(pos[x]){
				if(pos[x]>n) push(x,pos[x]);
				else{				
					if(prt) printf("1 %d\n",lft); else ans++;
					if(prt) printf("2 %d %d\n",pos[x],lft); else ans++;
					pop(pos[x]);
				}
			}
			else{
				int nxt=find(); //cerr<<k<<" find "<<nxt<<" "<<sav[nxt]<<" "<<l<<" "<<r<<endl; system("pause");
				if(nxt!=-1) push(x,nxt);
				else{
					bool flag=0;
					for(int j=k+1;j<=m;j++){
						int pj=pos[a[j]];
//						cout<<"check "<<j<<" "<<a[j]<<" "<<pj<<endl;
						if(a[k]==a[j]){
							push(a[k],lft);
							for(int i=k+1;i<j;i++){
								int ps=pos[a[i]];
								if(!ps) ps=con[a[i]];
								push(a[i],ps);
								if(!pos[a[i]]) con[a[i]]=ps;
							}
							push(a[k],lft); k=j;
							flag=1; break;
						}
						if(pj<=n){
							if(vis[pj]==k){
//								cout<<"error\n";
								push(a[k],lft);					
								for(int i=k+1;i<j;i++){
									int ps=pos[a[i]];
									if(!ps) ps=con[a[i]];
									push(a[i],ps);
									if(!pos[a[i]]) con[a[i]]=ps;									
								}
								push(a[j],pj); lft=pj; q[++r]=lft; q[++r]=lft+n;
							}
							else{
								if(prt) printf("1 %d\n",pj);else ans++;
								for(int i=k+1;i<j;i++){
									int ps=pos[a[i]];
									if(!ps) ps=con[a[i]];
									push(a[i],ps);
									if(!pos[a[i]]) con[a[i]]=ps;									
								}
								if(prt) printf("1 %d\n",lft);else ans++;
								if(prt) printf("2 %d %d\n",pj,lft);else ans++;
								pop(pj); pos[a[k]]=pj+n; sav[pj+n]=a[k];
							}
							flag=1; k=j; break;
						}
						if(vis[a[j]]==k){
							vis[a[j]]=0;
							continue;
						}
						if(vis[a[j]]==0){
							vis[a[j]]=k;
							continue;
						}
					}
//					if(!flag) puts("ERROR");
				}
			}
		}
	for(int k=1;k<=P;k++) vis[k]=sav[k]=pos[k]=con[k]=0;
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int t=read();
	while(t--){
		n=read(); m=read(); P=read(); 
		for(int k=1;k<=m;k++) a[k]=read();
		prt=0; solve();
		printf("%d\n",ans);
		prt=1; solve();
		ans=0;
	}
	return 0;
}
/*
1
2 4 2
1 2 1 2
1
3 10 5
1 2 3 4 5 2 3 4 5 1
*/
