#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,l,r) for(ll i=l,i##end=r;i<=i##end;++i)
#define Rep(i,l,r) for(ll i=l,i##end=r;i<i##end;++i)
#define FOR(i,l,r) for(ll i=l,i##end=r;i>=i##end;--i)
ll read(){
	ll v=0;bool f=1;char c=getchar();
	for(;'0'>c||c>'9';c=getchar())
	    if(c=='-') f = 0;
	for(;'0'<=c&&c<='9';c=getchar())
	    v = (v<<3)+(v<<1)+(c^48);
	return f?v:-v;
}
const ll N = 3e2+10;
const ll M = 2e6+10;
ll n,m,k;
ll a[M];
ll rs0[M<<1],rs1[M<<1];
namespace A{
ll wh[N<<1],wg[N<<1];
queue<ll> q;
void work(){
	while(!q.empty()) q.pop();
	For(i,1,k) wh[i] = 0;
	For(i,1,n+n) wg[i] = 0;
	For(i,1,n-1) q.push(i),q.push(n+i);
	ll t = 0;
	For(i,1,m){
		if(wh[a[i]]==0){
			ll x = q.front();q.pop();
			rs0[++t] = 1;rs1[t] = x%n;
		    wh[a[i]] = x;wg[x] = a[i];
		}
		else if(wh[a[i]]<=n){
			rs0[++t] = 1;rs1[t] = n;
			ll x = wh[a[i]];
			rs0[++t] = 2;rs1[t] = x;
			wg[x] = wg[x+n];wg[x+n] = 0;
			q.push(x+n);
		}else{
			ll x = wh[a[i]];
			rs0[++t] = 1;rs1[t] = x-n;
			wg[x] = wh[a[i]] = 0;
			q.push(x);
		}
	}
	printf("%lld\n",t);
	For(i,1,t){
		if(rs0[i]==1) printf("1 %lld\n",rs1[i]);
		else printf("2 %lld %lld\n",rs1[i],n);
	}
}
}
namespace B{
ll cnt,ok[N][N],rs2[M<<1],ttt;
bool dfs(ll p){
	if(p>m){
		For(i,1,n) if(ok[i][1]) return 0;
		return 1;
	}
	++cnt;if(cnt>m+m){--cnt;return 0;}
	For(i,1,n){
		rs0[cnt] = 1;rs1[cnt] = i;
		if(ok[i][1]==0){
			ok[i][1] = a[p];bool flag = 0;
			For(j,1,n){
				if(i!=j&&ok[j][1]==a[p]){
					rs0[++cnt] = 2;rs1[cnt] = i;rs2[cnt] = j;
					For(k,1,ttt-1) ok[j][k] = ok[j][k+1];
					ok[j][ttt] = 0;ok[i][1] = 0;
					if(dfs(p+1)) return 1;
					FOR(k,ttt-1,1) ok[j][k+1] = ok[j][k];
					ok[j][1] = a[p];flag = 1;--cnt;
				}
			}
			if(!flag) if(dfs(p+1)) return 1;
			ok[i][1] = 0;
		}else{
			ll k = 0;
			For(j,2,ttt) if(ok[i][j]==0){k = j;break;}
			if(k==0) continue;
			if(ok[i][k-1]==a[p]){
				ok[i][k-1] = 0;
				if(dfs(p+1)) return 1;
				ok[i][k-1] = a[p];
			}else{
			    ok[i][k] = a[p];
				if(dfs(p+1)) return 1;
				ok[i][k] = 0;
			}
		}
	} 
	--cnt;return 0;
}
void work(ll maxn){
	cnt = 0;ttt = maxn;
	For(i,1,n) For(j,1,ttt) ok[i][j] = 0;
	dfs(1);
	printf("%lld\n",cnt);
	For(i,1,cnt){
		if(rs0[i]==1)printf("1 %lld\n",rs1[i]);
		else printf("2 %lld %lld\n",rs1[i],rs2[i]);
	}
}
}
//namespace C{
//void work(){
//	For(i,1,m){
//		if(!vis[i]) vis[i] = 1,++num;
//		else 
//	}
//}
//}

int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	
	ll T=read();
	For(qwq,1,T){
		n=read(),m=read(),k=read();
		For(i,1,m) a[i]=read();
		if(T%10==1) A::work();
		else if(T%10==3) B::work(5);
		else B::work(n);
	}
	
	fclose(stdin);fclose(stdout);
	return 0;
}
