#include<bits/stdc++.h>
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define pt(x) cerr << #x << " = " << (x) << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 300 + 5, M = 2000000 + 5;
int n, m, k, a[M];
deque<int> b[N];
struct Op { int typ, x, y; };
mt19937 my_rand(time(0));
int rnd(int l, int r) {
	return l + my_rand() % (r - l + 1);
}
namespace case1 {
	vector<Op> ans;
	void solve() {
		ans.clear();
		rep(i, 1, n) b[i].clear();
		rep(i, 1, m) {
			int t = (a[i] - 1) % (n - 1) + 1;
			if(b[t].empty()) {
				ans.pb(Op{1, t, 0});
				b[t].pb(a[i]);
			}
			else if(b[t].back() == a[i]) {
				ans.pb(Op{1, t, 0});
				b[t].pop_back();
			}
			else if(b[t].front() == a[i]) {
				ans.pb(Op{1, n, 0});
				ans.pb(Op{2, t, n});
				b[t].pop_front();
			}
			else {
				ans.pb(Op{1, t, 0});
				b[t].pb(a[i]);
			}
		}
		printf("%d\n", (int)ans.size());
		for(Op x : ans) {
			if(x.typ == 1) printf("1 %d\n", x.x);
			else printf("2 %d %d\n", x.x, x.y);
		}
	}
}
namespace case2 {
	int c[N * 2];
	vector<Op> ans[M];
	int nw[N];
	void solve() {
		while(1) {
			int qwq = rnd(1, n * 2 - 1);
			c[0] = 0;
			rep(i, 1, n * 2 - 1) {
				c[i] = c[i-1] % (n - 1);
				if(i != qwq) c[i]++;
			}
			c[qwq] = 0;
			
			rep(i, 1, n) b[i].clear();
			rep(i, 1, m) {
				ans[i].clear();
				int t = c[a[i]];
				if(b[t].empty()) {
					ans[i].pb(Op{1, t, 0});
					b[t].pb(a[i]);
				}
				else if(b[t].back() == a[i]) {
					ans[i].pb(Op{1, t, 0});
					b[t].pop_back();
				}
				else if(b[t].front() == a[i]) {
					ans[i].pb(Op{1, n, 0});
					ans[i].pb(Op{2, t, n});
					b[t].pop_front();
				}
				else {
					ans[i].pb(Op{1, t, 0});
					b[t].pb(a[i]);
				}
			}
		}
	}
}
void work() {
	cin >> n >> m >> k;
	rep(i, 1, m) scanf("%d", &a[i]);
	if(k == 2 * n - 2) case1::solve();
	else case2::solve();
}
int main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	int T; cin >> T;
	while(T--) work();
	return 0;
}
/*
input
1
3 10 5
1 2 3 4 5 2 3 4 5 1
output
15
1 1
1 1
1 1
1 1
1 1
1 2
1 2
1 2
1 2
1 3
2 1 3
2 1 2
2 1 2
2 1 2
2 1 2
input
1
2 4 2
1 2 1 2
output
5
1 1
1 1
1 2
2 1 2
1 1

*/
