#include<bits/stdc++.h>
using namespace std;
const int M=2e6+5,N=605;
mt19937 rnd(time(0));
int n,m,k,a[M],aa[N];
int tp[N],bt[N];
int cnt,up[M],dn[M],v[M];
inline void solve() {
	scanf("%d%d%d",&n,&m,&k),cnt=0;
	for(int i=1; i<=m; i++)
		scanf("%d",&a[i]),up[i]=dn[i]=0;
	memset(tp,0,sizeof(tp));
	memset(bt,0,sizeof(bt));
	if(k==2*n-2) {
		vector<pair<int,int>> ans;
		for(int i=1; i<=m; i++) {
			int p=(a[i]+1)/2;
			if(!tp[p]||!bt[p]) {
				ans.push_back({p,0});
				tp[p]=bt[p]=++cnt;
				v[cnt]=a[i];
			} else {
				if(v[tp[p]]==a[i]) {
					ans.push_back({p,0});
					tp[p]=dn[tp[p]];
				} else if(v[bt[p]]==a[i]) {
					ans.push_back({n,0});
					ans.push_back({p,n});
					bt[p]=up[bt[p]];
				} else {
					ans.push_back({p,0});
					int qwq=++cnt;
					v[cnt]=a[i];
					dn[qwq]=tp[p];
					up[tp[p]]=qwq;
					tp[p]=qwq;
				}
			}
		}
		cout<<ans.size()<<'\n';
		for(auto i:ans) {
			if(!i.second) cout<<"1 "<<i.first<<'\n';
			else cout<<"2 "<<i.first<<" "<<i.second<<'\n';
		}
	} else if(n<=3) {
		for(int T=1; T<=k; T++) {
			bool flg=1,QAQ=0;cnt=0;
			vector<pair<int,int>> ans;
			memset(tp,0,sizeof(tp));
			memset(bt,0,sizeof(bt));
			for(int i=1; i<=m; i++) up[i]=dn[i]=0;
			for(int i=1,A; i<=m; i++) {
				if(a[i]==T) A=k;
				else if(a[i]<T) A=a[i];
				else A=a[i]-1;
				if(A==k) {
					ans.push_back({n,0});
					QAQ=!QAQ;
				} else {
					int p=(A+1)/2;
					if(!tp[p]||!bt[p]) {
						ans.push_back({p,0});
						tp[p]=bt[p]=++cnt;
						v[cnt]=a[i];
					} else {
						if(v[tp[p]]==a[i]) {
							ans.push_back({p,0});
							tp[p]=dn[tp[p]];
						} else if(v[bt[p]]==a[i]) {
							if(QAQ) {
								flg=0;
								break;
							}
							ans.push_back({n,0});
							ans.push_back({p,n});
							bt[p]=up[bt[p]];
						} else {
							ans.push_back({p,0});
							int qwq=++cnt;
							v[cnt]=a[i];
							dn[qwq]=tp[p];
							up[tp[p]]=qwq;
							tp[p]=qwq;
						}
					}
				}
			}
			if(flg) {
				cout<<ans.size()<<'\n';
				for(auto i:ans) {
					if(!i.second) cout<<"1 "<<i.first<<'\n';
					else cout<<"2 "<<i.first<<" "<<i.second<<'\n';
				}
				break;
			}
		}
	} else {
		for(int i=1; i<=k; i++) aa[i]=(i+1)/2;
		for(int T=1; T<=40; T++) {
			shuffle(aa+1,aa+k+1,rnd),cnt=0;
			for(int i=1; i<=m; i++) up[i]=dn[i]=0;
			memset(tp,0,sizeof(tp));
			memset(bt,0,sizeof(bt));
			bool flg=1,QAQ=0;
			vector<pair<int,int>> ans;
			for(int i=1,A; i<=m; i++) {
				A=aa[a[i]];
				if(A==n) {
					ans.push_back({n,0});
					QAQ=!QAQ;
				} else {
					int p=A;
					if(!tp[p]||!bt[p]) {
						ans.push_back({p,0});
						tp[p]=bt[p]=++cnt;
						v[cnt]=a[i];
					} else {
						if(v[tp[p]]==a[i]) {
							ans.push_back({p,0});
							tp[p]=dn[tp[p]];
						} else if(v[bt[p]]==a[i]) {
							if(QAQ) {
								flg=0;
								break;
							}
							ans.push_back({n,0});
							ans.push_back({p,n});
							bt[p]=up[bt[p]];
						} else {
							ans.push_back({p,0});
							int qwq=++cnt;
							v[cnt]=a[i];
							dn[qwq]=tp[p];
							up[tp[p]]=qwq;
							tp[p]=qwq;
						}
					}
				}
			}
			if(flg) {
				cout<<ans.size()<<'\n';
				for(auto i:ans) {
					if(!i.second) cout<<"1 "<<i.first<<'\n';
					else cout<<"2 "<<i.first<<" "<<i.second<<'\n';
				}
				break;
			}
		}
		return ;
	}
}
int main() {
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T;scanf("%d",&T);
	while(T--) solve();
	return 0;
}
