#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e6+7;
int T,n,m,k;
int a[N],now[1007],vis[1007][1007];
vector<int>deq[1007],mp[1007];
//queue<pair<int,int> >q;
struct Node {
	int op,l,r;
} ans[N<<1];
int cntans=0;
bool tp() {
	int p[1007];
	for(int i=1; i<=k; ++i) p[i]=0;
	for(int i=1; i<=n; ++i) {
		if(now[i]==deq[i].size()) continue;
		if(!p[deq[i][now[i]]]) p[deq[i][now[i]]]=i;
		else {
			int val=deq[i][now[i]],x=p[val];
			ans[++cntans].op=2,ans[cntans].l=x,ans[cntans].r=i;
			now[i]++,now[x]++;
			vis[i][val]--,vis[x][val]--;
			return 1;
		}
	}
	return 0;
}
signed main() {
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	scanf("%lld",&T);
	while(T--) {
		scanf("%lld%lld%lld",&n,&m,&k);
		for(int i=1; i<=n; ++i) {
			mp[i].clear();
			deq[i].clear();
			now[i]=0;
		}
//		while(q.size()) q.pop();
		cntans=0;
		for(int i=1; i<=k; ++i) {
			for(int j=1; j<=k; ++j) {
				vis[i][j]=0;
			}
		}
		for(int i=1; i<=m; ++i) scanf("%lld",a+i),mp[a[i]].push_back(i);
		for(int i=1; i<=m; ++i) {
			while(tp());
			int empty=0,chk=0;
			for(int j=1; j<=n; ++j)
				if(deq[j].size()==now[j]) {
					empty=j;
					break;
				}
//		printf("!%lld\n",empty);
			for(int j=1; j<=n; ++j) {
				if(now[j]==deq[j].size()) continue;
				if(deq[j][now[j]]==a[i]&&empty>0) {
					ans[++cntans].op=1,ans[cntans].l=empty;
					ans[++cntans].op=2,ans[cntans].l=empty,ans[cntans].r=j;
					now[j]++;
					vis[j][a[i]]--;
					chk=1;
					break;
				}
			}
			if(chk) continue;
			for(int j=1; j<=n; ++j) {
				if(now[j]==deq[j].size()) continue;
				if(deq[j][deq[j].size()-1]==a[i]) {
					ans[++cntans].op=1,ans[cntans].l=j;
					deq[j].erase(--deq[j].end());
					vis[j][a[i]]--;
//					cout<<j<<"    !!    "<<a[i]<<endl;
					chk=1;
					break;
				}
			}
			if(chk) continue;
			if(empty!=n) {
				ans[++cntans].op=1,ans[cntans].l=empty;
				vis[empty][a[i]]++;
				deq[empty].push_back(a[i]);
			} else {
				int chk=0;
				for(int j=1; j<n; ++j) {
					if(vis[j][a[i]]>0) {
						ans[++cntans].op=1,ans[cntans].l=j;
						deq[j].push_back(a[i]);
						chk=1;
						vis[j][a[i]]++;
						break;
					}
				}
				if(!chk) {
					for(int j=1; j<=n; ++j) {
						int kkkk=0;
						for(int K=1; K<=k; ++K) {
							if(vis[j][K]) kkkk++;
						}
						if(kkkk==1) {
							ans[++cntans].op=1,ans[cntans].l=j;
							deq[j].push_back(a[i]);
							chk=1;
							vis[j][a[i]]++;
							chk=1;
							break;
						}
					}
					if(!chk) {
						int xx=*upper_bound(mp[a[i]].begin(),mp[a[i]].end(),i);
						for(int j=1; j<n; ++j) {
							if(!deq[j].size()||now[j]==deq[j].size()) continue;
							int K=deq[j][deq[j].size()-1],KK=deq[j][now[j]];
							int yy=*upper_bound(mp[K].begin(),mp[K].end(),i);
							int yyy=*upper_bound(mp[KK].begin(),mp[KK].end(),i);
							if(yy>xx) {
								deq[j].push_back(a[i]);
								vis[j][a[i]]++;
								chk=1;
								ans[++cntans].op=1,ans[cntans].l=j;
								break;
							} else if(yyy<xx) {
								deq[j].push_back(a[i]);
								chk=1;
								vis[j][a[i]]++;
								ans[++cntans].op=1,ans[cntans].l=j;
								break;
							}
						}
					}
				}
			}
		}
		while(tp());
		printf("%lld\n",cntans);
		for(int i=1; i<=cntans; ++i) {
			if(ans[i].op==1) printf("1 %lld\n",ans[i].l);
			if(ans[i].op==2) printf("2 %lld %lld\n",ans[i].l,ans[i].r);
			ans[i].op=ans[i].l=ans[i].r=0;
		}
//		puts("!");
	}

	return 0;
}