#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int N=10004;
int cnt,anscnt,tf,T,n,m,k,a[N],path[N],vis[N];
pair<int,pair<int,int> >  p[2333],ans[2000006];
deque <int> q[5];
bool check(){
	cnt=0;
	for (int i=1;i<=n;i++) while(!q[i].empty()) q[i].pop_back();
//	cout<<"path:";for(int i=1;i<=m;i++)cout<<path[i]<<' ';cout<<endl;	
	for (int i=1;i<=m;i++) {
			if (!q[path[i]].empty()) {
			if (q[path[i]].back()==a[i]) {
					p[++cnt]={1,{path[i],0}};
					q[path[i]].pop_back();
					continue;
				}
			}
			q[path[i]].push_back(a[i]);
			p[++cnt]={1,{path[i],0}};
			for (int i=1;i<=n;i++) {
				if (path[i]==i) continue;
				if ((!q[i].empty())&&q[i].front()==q[path[i]].front()) {
					p[++cnt]={2,{i,path[i]}};
					q[i].pop_front(); q[path[i]].pop_front();
				}
			}
		}
	for (int i=1;i<=n;i++) {
		if (!q[i].empty()) return 0;
	}
//	cout<<"cnt="<<cnt<<endl;cout<<"path:";for(int i=1;i<=m;i++)cout<<path[i]<<' ';cout<<endl;
	return 1;
}
void rec() {
	anscnt=cnt;
	for (int i=1;i<=anscnt;i++) ans[i]=p[i];
	tf=1;
}
void dfs(int x) {
	if (tf) return ;
	if (x==m) {
		if (check()) {
			rec();
		}
		return ;
	}
	for (int i=1;i<=n;i++) {
		path[x+1]=i;
		dfs(x+1);
	}
}
int pei(int x) {
	if (x>n-1) return x-n-1;
	return x+n-1;
}
signed main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin>>T;
	if (T!=1001) {
		while (T--) {
			cin>>n>>m>>k; tf=0;
			for (int i=1;i<=m;i++) cin>>a[i];
			dfs(0);
			cout<<anscnt<<'\n';
			for (int i=1;i<=anscnt;i++) {
				cout<<ans[i].first<<' ';
				cout<<ans[i].second.first<<' ';
				if (ans[i].first==2) cout<<ans[i].second.second;
				cout<<'\n';
			}		
		}
	}
	else {
		while (T--) {
			cin>>n>>m>>k; anscnt=0;
//			cout<<"qwq"<<endl;
			for (int i=1;i<=m;i++) cin>>a[i];
			for (int i=1;i<=k;i++) vis[i]=0;
			for (int i=1;i<=m;i++) {
		//		cout<<"i="<<i<<" anscnt="<<anscnt<<endl;
				int t=a[i]%(n-1);
				if (t==0) t=n-1;
				if (vis[a[i]]==1) {
					ans[++anscnt]={1,{n,0}};
					ans[++anscnt]={2,{t,n}};
					vis[a[i]]=0;
					vis[pei(a[i])]=1;
				}
				else if (vis[a[i]]==2) {
					ans[++anscnt]={1,{t,0}};
					vis[a[i]]=0;
				}				
				else {
					ans[++anscnt]={1,{t,0}};
					if (vis[pei(a[i])]) {
						vis[pei(a[i])]=1;
						vis[a[i]]=2;
					}
					else vis[a[i]]=1;
				}	
			}
				cout<<anscnt<<'\n';
				for (int i=1;i<=anscnt;i++) {
					cout<<ans[i].first<<' ';
					cout<<ans[i].second.first<<' ';
					if (ans[i].first==2) cout<<ans[i].second.second;
					cout<<'\n';
				}				
		}
		
	}
	
	
	
	return 0;
}

/*
4
2 4 2
1 2 1 2
2 4 2
1 2 1 2
2 4 2
1 2 1 2
3 10 4
1 2 3 4 1 2 3 4 1 1

1
3 10 4
1 2 3 4 1 2 3 4 1 1


2
3 10 4
1 2 3 4 1 2 3 4 1 1
2 4 2
1 2 1 2
*/
