#include<bits/stdc++.h>
using namespace std;
mt19937 rnd(0);
int t,n,m,k,i,j;
struct opt {
	int op,l,r;
};
deque<int> a[305];
queue<opt> ans;
int b[2000007];
int main() {
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	cin>>t;
	while(t--) {
		cin>>n>>m>>k;
		for(i=1; i<=m; ++i)
			cin>>b[i];
		while(1) {
			for(i=1; i<=m; ++i) {
				bool ok=1;
				int wh=-1;
				for(j=1; j<=n; ++j) {
					if(!a[j].empty()&&a[j].front()==b[i]) {
						a[j].pop_front();
						ans.push({1,j,0});
						ok=0;
					} else if(a[j].empty())wh=j;
				}
				if(wh!=-1&&ok) {
					for(j=1; j<=n; ++j)
						if(!a[j].empty()&&a[j].back()==b[i]) {
							a[j].pop_back();
							ans.push({1,wh,0});
							ans.push({2,j,wh});
							ok=0;
						}
				}
				if(ok){
					int wh=rnd();
					if(wh<0)wh=-wh;
					wh%=n;
					wh++;
					ans.push({1,wh,0});
					a[wh].push_front(b[i]);
				}
			}
			bool ok=0;
			for(i=1;i<=n;++i){
				ok|=a[i].empty();
				a[i].clear();			
			}
			if(!ok){
				cout<<ans.size()<<'\n';
				while(!ans.empty()){
					auto x=ans.front();
					ans.pop();
					cout<<x.op<<' '<<x.l;
					if(x.op==2)cout<<' '<<x.r;
					cout<<'\n';
				}
			}
		}
	}
	return 0;
}