//k=2n-2
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mkp make_pair
#define fi first
#define se second
#define ls(x) ((x)<<1)
#define rs(x) ((x)<<1|1)
const int N = 310, M = 2e6 + 10;
int n, m, k, a[M];
int st[N][2], top[N];
//0底 1顶
vector<pair<int, int> >ans;
void solve1() {
	ans.clear();
	int gap = k / 2;
	for(int i = 1; i <= m; i++) {
		int id = ((a[i] > gap) ? a[i] - gap : a[i]);
		if(top[id]) {
			if(st[id][0] == a[i]) {
				ans.push_back(mkp(n, 0));
				ans.push_back(mkp(id, n));
				st[id][0] = st[id][1]; st[id][1] = 0;
				top[id]--;
			} else if(st[id][top[id] - 1] == a[i]){
				ans.push_back(mkp(id, 0));
				top[id]--;
			} else {
				ans.push_back(mkp(id, 0));
				st[id][top[id]++] = a[i];
			}
		} else {
			ans.push_back(mkp(id, 0));
			st[id][top[id]++] = a[i];
		}
	}
	int sz = ans.size();
	printf("%d\n", sz);
	for(int i = 0; i < sz; i++) {
		if(ans[i].se == 0) printf("1 %d\n", ans[i].fi);
		else printf("2 %d %d\n", ans[i].fi, ans[i].se);
	}
	return;
}
int main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	int T; scanf("%d", &T);
	while(T--) {
		scanf("%d%d%d", &n, &m, &k);
		for(int i = 1; i <= m; i++)
			scanf("%d", &a[i]);
		if(k == 2 * n - 2) solve1();	
	}
	return 0;
}
/*
5 20 8
1 4 7 2 2 3 3 5 8 1 5 6 1 2 3 4  8 6 7 4
*/