#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pa pair<int,int>
#define mp make_pair
#define fi first
#define se second

const int N=305,M=2e6+5;
pa ans[N<<1];
int a[M],b[N<<1],gen[N<<1],c[N<<1];
int i,n,m,k,x,y,T,cnt,tmp,sum;
bool use[N];
priority_queue<int,vector<int>,greater<int> >q,qq;
deque<int>xl[N];
queue<int>p;
inline int read(){
	register int x=0,f=1;register char c=getchar();
	while(c<'0'||c>'9') f=(c=='-'?-1:1),c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
	return x*f;
}
void solve(){
	for(i=1;i<=m;++i){
		x=read();
		if(!b[x]){
		    b[x]=q.top();
		    xl[b[x]].push_front(x);
		    if(xl[b[x]].size()>1) gen[x]=0,q.pop();else gen[x]=1;
		    ans[++cnt]=mp(-1,b[x]);
		}else{
			if(gen[x]){
				ans[++cnt]=mp(-1,n);
				ans[++cnt]=mp(b[x],n);
				xl[b[x]].pop_back();
				q.push(b[x]);
			}else{
				ans[++cnt]=mp(-1,b[x]);
				xl[b[x]].pop_front();
				q.push(b[x]);
			}
			b[x]=0;
		}
	}
	printf("%d\n",cnt);
	for(i=1;i<=cnt;++i)
	    if(ans[i].fi==-1)
	        printf("1 %d\n",ans[i].se);else
	        printf("2 %d %d\n",ans[i].fi,ans[i].se);
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	T=read();
	while(T--){
		n=read();m=read();k=read();
		cnt=tmp=sum=0;
		for(i=1;i<=n;++i) q.push(i);
		if(k==2*n-2){solve();continue;}
		for(i=1;i<=m;++i) a[i]=read();
		for(i=1;i<=m;++i){
			++b[a[i]];
			if(b[a[i]]==1) ++sum;else
			b[a[i]]=0,--sum;
			if(sum==n) c[a[i+1]]=++tmp;
		}
		memset(b,0,sizeof(b));
		for(i=1;i<=n;++i){
			while(use[qq.top()]) qq.pop();
			if(b[a[i]]&&gen[a[i]]>=0){
				if(gen[a[i]]){
					ans[++cnt]=mp(-1,b[a[i]]);
					xl[b[a[i]]].pop_back();
					if(xl[b[a[i]]].size()==1) qq.push(b[a[i]]),use[b[a[i]]]=false;else
					if(xl[b[a[i]]].size()==0) q.push(b[a[i]]),use[b[a[i]]]=true;
				}else
				if(!q.empty()){
					ans[++cnt]=mp(-1,n);
					ans[++cnt]=mp(b[a[i]],n);
					xl[b[a[i]]].pop_back();
					if(xl[b[a[i]]].size()==1) qq.push(b[a[i]]),use[b[a[i]]]=false;else
					if(xl[b[a[i]]].size()==0) q.push(b[a[i]]),use[b[a[i]]]=true;
				}else{
					gen[xl[b[a[i]]].front()]=0;
					b[a[i]]=qq.top();gen[a[i]]=1;
					xl[b[a[i]]].push_front(a[i]);
					ans[++cnt]=mp(-1,b[a[i]]);
					qq.pop();
				}
				b[a[i]]=0;
			}else
			if(!c[a[i]]){
				if(qq.size()>1){
					gen[xl[b[a[i]]].front()]=0;
					b[a[i]]=qq.top();gen[a[i]]=1;
					xl[b[a[i]]].push_front(a[i]);
					ans[++cnt]=mp(-1,b[a[i]]);
					qq.pop();
				}else{
					b[a[i]]=q.top();gen[a[i]]=2;
					xl[b[a[i]]].push_front(a[i]);
					ans[++cnt]=mp(-1,b[a[i]]);
					q.pop();qq.push(b[a[i]]);p.push(b[a[i]]);
				}
			}else{
				if(q.size()>1){
					b[a[i]]=q.top();gen[a[i]]=2;
					xl[b[a[i]]].push_front(a[i]);
					ans[++cnt]=mp(-1,b[a[i]]);
					q.pop();qq.push(b[a[i]]);p.push(b[a[i]]);
				}else{
					b[a[i]]=p.front();
					gen[xl[p.front()].front()]=(gen[xl[p.front()].front()]==2?0:-1);
					xl[p.front()].push_front(a[i]);
					ans[++cnt]=mp(-1,p.front());
					if(xl[p.front()].size()==2) use[xl[p.front()].size()]=true;
					p.pop();
				}
			}
		}
		printf("%d\n",cnt);
    	for(i=1;i<=cnt;++i)
	        if(ans[i].fi==-1)
	            printf("1 %d\n",ans[i].se);else
	            printf("2 %d %d\n",ans[i].fi,ans[i].se);
	}
	return 0;
}
