#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define Fin(x) freopen(x, "r", stdin)
#define Fout(x) freopen(x, "w", stdout)
#define Fio(x) Fin(x".in"), Fout(x".out")
#define fi first
#define se second
using namespace std;
const int maxn = 2e6 + 10, maxm = 2e6 + 10;
struct Stack{
	deque<int> q;
	bool empty(){return q.empty();}
	int size(){return q.size();}
	void push(int x){
		if(!q.empty() && q.back() == x) q.pop_back();
		else q.pb(x);
	}
	int front(){return q.front();}
	int back(){return q.back();}
	void pop_front(){return q.pop_front();}
	void pop_back(){return q.pop_back();}
}q[maxn];
struct Query{
	int opt, x, y;
	Query(){} Query(int w, int a, int b = 0){opt = w, x = a, y = b;}
};
vector<Query> ans;
int T, n, m, k, a[maxm], cnt[maxn], ind[maxn], nxt[maxn];
int used[maxn], ban[maxm], ins, res[maxm], top, pos[maxn], bel[maxm];
vector<pair<int, int>> seg;
//void solve(vector<int> x, vector<int> y, int st){
//	int cur = 1;
//	for(int i : x){
//		if(!ban[i]) ind[a[i]] = i;
//		else bel[i] = n, ind[a[i]] = 2;
//	}
//	vector<int> nx, ny;
//	for(int i = 0, j; i < (int)y.size(); i = j + 1){
//		j = i; int p = ind[y[i]];
//		while(j + 1 < (int)y.size() && p + 1 < (int)x.size() && a[y[j + 1]] == a[x[p + 1]]) j++, p++;
//		if(j == i) nx.pb(p), ny.pb(i);
//		else{
//			for(int k = i; k <= j; k++) bel[y[k]] = st;
//			for(int k = ind[y[i]]; k <= p; k++) bel[x[p]] = st + 1;
//			st += 2;
//		}
//	}
//	if(nx.size() == x.size()){
//		for(int i = 0; i < nx.size(); i++);
//	}
//}
// bailanle
int main(){
	Fio("meow");
	scanf("%d", &T);
	while(T--){
		scanf("%d%d%d", &n, &m, &k), ans.clear();
		for(int i = 1; i <= n; i++) cnt[i] = used[i] = 0;
		for(int i = 1; i <= m; i++) scanf("%d", &a[i]), cnt[a[i]]++, ban[i] = 0;
		if(k == n * 2 - 2){
			for(int i = 1; i <= m; i++){
				int ind = (a[i] + 1) / 2;
				if(q[ind].empty()) q[ind].push(a[i]), ans.pb(Query(1, ind));
				else if(q[ind].front() == a[i]) ans.pb(Query(1, n)), ans.pb(Query(2, ind, n)), q[ind].pop_front();
				else if(q[ind].back() == a[i]) ans.pb(Query(1, ind)), q[ind].push(a[i]);
				else ans.pb(Query(1, ind)), q[ind].push(a[i]);
//		printf("qwq %d\n", (int)ans.size());
			}
		}else if(n == 2){
			for(int i = 1; i <= m; i++){
				if(i < m && a[i] == a[i + 1]) ans.pb(Query(1, 1)), ans.pb(Query(1, 1)), i++;
				else if(!q[1].empty() && a[i] == q[1].back()) ans.pb(Query(1, 1)), q[1].push(a[i]);
				else if(!q[2].empty() && a[i] == q[2].back()) ans.pb(Query(1, 2)), q[2].push(a[i]);
				else if(!q[1].empty() && q[2].empty() && a[i] == q[1].front()) ans.pb(Query(1, 2)), ans.pb(Query(2, 1, 2)), q[1].pop_front();
				else if(!q[2].empty() && q[1].empty() && a[i] == q[2].front()) ans.pb(Query(1, 1)), ans.pb(Query(2, 1, 2)), q[2].pop_front();
				else if(q[1].empty()) ans.pb(Query(1, 1)), q[1].push(a[i]);
				else if(q[2].empty()) ans.pb(Query(1, 2)), q[2].push(a[i]);
				else{
					int nxt = i + 1;
					while(nxt + 1 <= m && a[nxt] == a[nxt + 1]) nxt += 2;
					if(!q[1].empty() && a[nxt] == q[1].back()) ans.pb(Query(1, 2)), q[2].push(a[i]);
					else if(!q[2].empty() && a[nxt] == q[2].back()) ans.pb(Query(1, 1)), q[1].push(a[i]);
					else assert(0);
				}
			}
		}
		printf("%d\n", (int)ans.size());
		for(auto p : ans){
			if(p.opt == 1) printf("1 %d\n", p.x);
			else printf("2 %d %d\n", p.x, p.y);
		}
	}
	return 0;
}

