#include <bits/stdc++.h>
#define rep(i,j,k) for(int i = (j);i <= (k);i++)
#define per(i,j,k) for(int i = (j);i >= (k);i--)
#define eb emplace_back
#define pii pair <int,int>
#define mkp make_pair
#define ll long long
#define ull unsigned long long
using namespace std;

void chkmin(int &x,int y){
	if(x > y) x = y;
}

void chkmax(int &x,int y){
	if(x < y) x = y;
}

void chkmin(ll &x,ll y){
	if(x > y) x = y;
}

void chkmax(ll &x,ll y){
	if(x < y) x = y;
}
int T,n,m,k;
int col[2000005];

vector <int> stk[5],tmp[5];

int cnt;
int ans[4000005][2];

void op1(int x){
	++cnt;
	ans[cnt][0] = x;ans[cnt][1] = -1;
}

void op2(int x,int y){
	stk[x].pop_back();stk[y].pop_back();
	++cnt;
	ans[cnt][0] = x;ans[cnt][1] = y;
}
int flg;

void dfs(int p){
	if(p == m + 1){
		//printf("check?");
		tmp[1] = stk[1];
		tmp[2] = stk[2];
		tmp[3] = stk[3];
		reverse(stk[1].begin(),stk[1].end());
		reverse(stk[2].begin(),stk[2].end());
		reverse(stk[3].begin(),stk[3].end());
		while(stk[1].size() + stk[2].size() + stk[3].size()){
			int a = -1,b = -2,c = -3;
			if(!stk[1].empty()) a = stk[1].back();
			if(!stk[2].empty()) b = stk[2].back();
			if(!stk[3].empty()) c = stk[3].back();
			
			if(a == b){
				op2(1,2);
				continue;	
			}
			if(b == c){
				op2(2,3);
				continue;
			}
			if(a == c){
				op2(1,3);
				continue;
			}
			while(cnt && ans[cnt][1] != -1) cnt--;
			swap(stk[1],tmp[1]);
			swap(stk[2],tmp[2]);
			swap(stk[3],tmp[3]);
			return;
		}
		//rep(i,1,cnt) printf("%d %d\n",ans[i][0],ans[i][1]);
		flg = 1;
		return;
	}
	op1(1);	
	if(stk[1].size() && stk[1].back() == col[p]){
		stk[1].pop_back();
		dfs(p + 1);
		if(flg) return;
		stk[1].eb(col[p]);
	}else{
		stk[1].eb(col[p]);
		dfs(p + 1);
		if(flg) return;
		stk[1].pop_back();
	}
	
	cnt--;
	
	op1(2);
	if(stk[2].size() && stk[2].back() == col[p]){
		stk[2].pop_back();
		dfs(p + 1);
		if(flg) return;
		stk[2].eb(col[p]);
	}else{
		stk[2].eb(col[p]);
		dfs(p + 1);
		if(flg) return;
		stk[2].pop_back();
	}
	cnt--;	
	
	op1(3);
	if(stk[3].size() && stk[3].back() == col[p]){
		stk[3].pop_back();
		dfs(p + 1);
		if(flg) return;
		stk[3].eb(col[p]);
	}else{
		stk[3].eb(col[p]);
		dfs(p + 1);	
		if(flg) return;
		stk[3].pop_back();
	}
	cnt--;		
}

void prt(){
	printf("%d\n",cnt);
	rep(i,1,cnt){
		if(ans[i][1] == -1) printf("1 %d\n",ans[i][0]);
		else printf("2 %d %d\n",ans[i][0],ans[i][1]);
	}
}

void solve(){
	scanf("%d%d%d",&n,&m,&k);
	cnt = 0;
	rep(i,1,m) scanf("%d",&col[i]);
	flg = 0;
	dfs(1);
	prt();
}

int cur[305][2],id[605];

void solve1(){
	scanf("%d%d%d",&n,&m,&k);
	rep(i,1,n) cur[i][0] = cur[i][1] = 0;
	rep(i,1,k) id[i] = 0;
	
	cnt = 0;
	rep(i,1,m){
		scanf("%d",&col[i]);
		if(id[col[i]]){
			int p = id[col[i]];
			if(cur[p][0] == col[i]){
				++cnt;
				ans[cnt][0] = n;ans[cnt][1] = -1;
				++cnt;
				ans[cnt][0] = p;ans[cnt][1] = n;
				cur[p][0] = cur[p][1];
				cur[p][1] = 0;
			}else{
				++cnt;
				ans[cnt][0] = p;ans[cnt][1] = -1;
				cur[p][1] = 0;
			}
			id[col[i]] = 0;
		}else{
			rep(j,1,n - 1){
				if(!cur[j][1]){
					id[col[i]] = j;
					if(!cur[j][0]){
						cur[j][0] = col[i];
					}else{
						cur[j][1] = col[i];
					}
					++cnt;
					ans[cnt][0] = j;ans[cnt][1] = -1;
					break;
				}
			}
		}
	}
	prt();
}

int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	scanf("%d",&T);
	if(T % 10 == 1){
		while(T--) solve1();
		return 0;
	}
	while(T--) solve();
	return 0;
}
