#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i) 
#define R(i, j, k) for(int i = (j); i >= (k); --i) 
#define ll long long 
#define vi vector < int > 
#define ull unsigned long long 
#define sz(a) ((int) (a).size())
#define me(a, x) memset(a, x, sizeof(a)) 
using namespace std;
const int N = 2e6 + 7, M = N * 2, mod = 998244353;
int n, m, k;
int a[N], cnt[N], op[N];

int cur[N], lst[N], mat[N];
bool win;

mt19937_64 orz(time(0) ^ *new int);

int qo[M], qx[M], qy[M], all;

int arr[N][11], tp[N];
int qc[N];

int curr, lim = 0;
void do1(int p) {
	assert(1 <= p && p <= n);
	++curr;
	++all, qo[all] = 1, qx[all] = p, ++lim, qc[curr] = p;
	arr[p][++tp[p]] = curr;
	
	if(tp[p] > 1 && a[arr[p][tp[p] - 1]] == a[arr[p][tp[p]]])
		tp[p] -= 2, lim -= 2;
}

void do2(int x, int y) {
	assert(1 <= x && x <= n);
	assert(1 <= y && y <= n);
	assert(x != y);
	
	++all, qo[all] = 1, qx[all] = x, qy[all] = y, lim -= 2;
	
	assert(a[arr[x][1]] == a[arr[y][1]]);
	L(i, 1, tp[x] - 1) arr[x][i] = arr[x][i + 1];
	--tp[x];
	L(i, 1, tp[y] - 1) arr[y][i] = arr[y][i + 1];
	--tp[y];
}

void solve(int x) {
	if(!op[x]) {
		int mt = mat[x], p = qc[mt];
		assert(a[x] == a[mt]);
		if(mt == arr[p][tp[p]]) {
			do1(p);
		} else {
			assert(mt == arr[p][1]);
			int emp = 0;
			L(i, 1, n) if(!tp[i]) emp = i;
			assert(emp > 0);
			do1(emp);
			do2(emp, p);
		}
		return ;
	}
	int cntemp = 0, ovo = 0;
	L(i, 1, n) if(tp[i] == 0) {
		++cntemp, ovo = i;
		if(cntemp == 2) 
			return do1(i);
	}
	int mx = 1e9, pos = 0;
	L(i, 1, n) 
		if(tp[i] == 1 && mat[arr[i][tp[i]]] < mx) 
			pos = i, mx = mat[arr[i][tp[i]]];
	if(!pos) {
		L(i, 1, n) 
			if(tp[i] == 2 && mat[arr[i][1]] < mat[arr[i][2]]) {
				pos = i;
				break;
			}
		if(!pos) 
			pos = ovo;
	} 
	do1(pos);
}

void dfs(int x) {
	if(x > m) {
		win = true;
		return ;
	}
	if(n == 2) {
		if(op[x] && !op[x + 1]) {
			int p = qc[mat[x + 1]];
			if(mat[x] == x + 1) {
				solve(x);
				solve(x + 1);
			} else if(tp[1] == 1 && tp[2] == 1) {
				do1(3 - p);
				solve(x + 1);
			} else {
				if(arr[p][1] == mat[x + 1]) {
					do1(p);
				} else do1(3 - p);
				solve(x + 1);
			}
		} else {
			solve(x);
			solve(x + 1);
		}
		dfs(x + 2);
		return ;
	}
	if(op[x] && !op[x + 1] && arr[qc[mat[x + 1]]][1] == mat[x + 1]) {
		int p = qc[mat[x + 1]];
		bool exist = 0;
		L(i, 1, n) 
			if(tp[i] == 0) 
				exist = 1;
		if(exist) {
			do1(p);
			solve(x + 1);
			dfs(x + 2);
			return ;
		} else {
			solve(x);
			solve(x + 1);
			dfs(x + 2);
		}
		return ;
	}
	solve(x);
	solve(x + 1);
	dfs(x + 2);
}

void Main() {
	win = 0, curr = 0;
	cin >> n >> m >> k;
	L(i, 1, m) {
		cin >> a[i];
		cnt[a[i]] ^= 1;
		op[i] = cnt[a[i]];
		if(!op[i]) {
			mat[lst[a[i]]] = i;
			mat[i] = lst[a[i]];
		}
		lst[a[i]] = i;
	}
	dfs(1);
	
	cout << all << '\n';
	L(i, 1, all) {
		if(qo[i] == 1) {
			cout << qo[i] << ' ' << qx[i] << '\n';
		} else {
			cout << qo[i] << ' ' << qx[i] << ' ' << qy[i] << '\n';
		}
	}
	
	curr = 0;
	all = 0;
	L(i, 1, max(n, max(m, k))) 
		cnt[i] = 0, lst[i] = 0, mat[i] = 0, tp[i] = 0, qc[i] = 0;
}
int main() {
//	return system("fc meow1.out meow1.ans"), 0;
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t;
	cin >> t;
	while(t--) Main();
	return 0;
}
