//不向抑郁与焦虑投降，这个世界终会有我们存在的地方。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<cassert>
#include<tuple>
#include<vector>
#define siz(x) int((x).size())
#define all(x) std::begin(x),std::end(x)
#define fi first
#define se second
using std::cin;using std::cout;
using std::min;using std::max;
template<typename any>inline void cmin(any &x,const any &y){if(x>y)x=y;}
template<typename any>inline void cmax(any &x,const any &y){if(x<y)x=y;}
using loli=long long;
using pii=std::pair<int,int>;
using bsi=std::basic_string<int>;
using bsc=std::string;
template<typename any>inline any get(){any x;cin>>x;return x;}
constexpr int N=2e6+2,M=602;
int n,m,k,a[N];
std::vector<pii>ans;
namespace sub2{
	void solve(){
		bsi s1,s2;
		for(int i=1;i<=m;i++){
			if(!s1.empty()&&s1.back()==a[i]){
				s1.pop_back();
				ans.emplace_back(2,0);
				ans.emplace_back(1,2);
				continue;
			}
			if(!s2.empty()&&s2.back()==a[i]){
				s2.pop_back();
				ans.emplace_back(1,0);
				ans.emplace_back(1,2);
				continue;
			}
			if(a[i]==a[i+1]){s1+=a[i];ans.emplace_back(1,0);continue;}
			if(s1.empty()){s1+=a[i];ans.emplace_back(1,0);continue;}
			if(s2.empty()){s2+=a[i];ans.emplace_back(2,0);continue;}
			if(s1.back()==a[i+1]){s2+=a[i];ans.emplace_back(2,0);continue;}
			if(s2.back()==a[i+1]){s1+=a[i];ans.emplace_back(1,0);continue;}
		}
		cout<<siz(ans)<<'\n';
		for(auto it:ans){
			int x,y;std::tie(x,y)=it;
			if(y)cout<<"2 "<<x<<' '<<y<<'\n';
			else cout<<"1 "<<x<<'\n';
		}
	}
}
namespace sub_{
	bsi s[M],col[M];
	int cnt[M];
	bool flag=false;
	void dfs(int i){
		if(flag)return;
		if(i==m+1){
			if(siz(col[0])==n){
				for(auto it:ans){
					int x,y;std::tie(x,y)=it;
					if(y)cout<<"2 "<<x<<' '<<y<<'\n';
					else cout<<"1 "<<x<<'\n';
				}
				flag=true;
				return;
			}else return;
		}
		if(!col[a[i]].empty()){
			int p=col[a[i]].back();
			col[a[i]].pop_back();
			ans.emplace_back(p==1?2:1,0);
			ans.emplace_back(p==1?2:1,p);
			s[p].pop_back();
			if(!s[p].empty())col[s[p].back()]+=p;
			else col[0]+=p;
			dfs(i+1);
			if(flag)return;
			if(!s[p].empty())col[s[p].back()].pop_back();
			else col[0].pop_back();
			s[p]+=a[i];
			ans.pop_back();
			ans.pop_back();
			col[a[i]]+=p;
		}
		if(!col[0].empty()){
			int p=col[0].back();
			col[0].pop_back();
			ans.emplace_back(p,0);
			col[a[i]]+=p;
			s[p]+=a[i];
			dfs(i+1);
			if(flag)return;
			s[p].pop_back();
			col[a[i]].pop_back();
			ans.pop_back();
			col[0]+=p;
		}
		for(int j=k;j>=1;j--)if(!col[j].empty()){
			int p=col[j].back();
			col[j].pop_back();
			s[p]+=a[i];
			col[a[i]]+=p;
			ans.emplace_back(p,0);
			dfs(i+1);
			if(flag)return;
			ans.pop_back();
			col[a[i]].pop_back();
			s[p].pop_back();
			col[j]+=p;
		}
	}
	void solve(){
		for(int i=1;i<=n;i++)col[0]+=i;
		dfs(1);
	}
}
signed main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	std::ios::sync_with_stdio(false);cin.tie(nullptr);
	int T;cin>>T;while(T--){
		cin>>n>>m>>k;
		for(int i=1;i<=m;i++)cin>>a[i];
		ans.clear();
		if(n>=2&&k<=3){sub2::solve();continue;}
		sub_::solve();
	}
	return 0;
}