// ????? T2 >>>>>> T3 ????
#include<bits/stdc++.h>
using namespace std;

//#define int long long
#define PB emplace_back
#define siz(a) ((int) (a.size()))
#define vi vector<int>
#define ll long long
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)

const int N = 2e6, M = 300;
int T, a, b, c, p[M * 2 + 5], q[N + 5], w[M * 4 + 5], s[N + 5];
deque<int> qu[M + 5];
set<int> nul;
struct pii {
	int x, y, z;
};
vector<pii> ans;

#define ls n << 1
#define rs n << 1 | 1
void ins(int n, int l, int r, int k, int p) {
	if(l == r) return w[n] = p, void();
	int mid = (l + r) >> 1;
	if(k <= mid) ins(ls, l, mid, k, p);
	else ins(rs, mid + 1, r, k, p);
	w[n] = max(w[ls], w[rs]);
}
void add(int n, int m) {
	qu[n].push_back(m);
	if(siz(qu[n]) == 1) nul.erase(n);
	ans.PB((pii) {1, n});
	ins(1, 1, a, n, m);
}
void delr(int n) {
	qu[n].pop_back();
	if(siz(qu[n]) == 0) {
		nul.insert(n);
		ins(1, 1, a, n, 0);
	}
	else ins(1, 1, a, n, qu[n].back());
}
void dell(int n) {
	qu[n].pop_front();
	if(siz(qu[n]) == 0) {
		nul.insert(n);
		ins(1, 1, a, n, 0);
	}
}

signed main() {
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	for(cin >> T; T--; ) {
		cin >> a >> b >> c;
		rep(i, 1, a) qu[i].clear();
		rep(i, 1, c) p[i] = 0;
		rep(i, 1, a * 4) w[i] = 0;
		nul.clear();
		rep(i, 1, a) nul.insert(i);
		rep(i, 1, b) cin >> s[i];
		rep(i, 1, b) {
			if(!p[s[i]]) p[s[i]] = i;
			else q[i] = p[s[i]], q[p[s[i]]] = i, p[s[i]] = 0;
		}
//		cout << q[18] << endl;
		ans.clear();
		rep(i, 1, b) {
//			cout << i << endl;
			if(q[i] > i) {
				int x = 0;
				rep(j, 1, a) if(siz(qu[j]) && qu[j].back() > q[i]) {
					if(!x) x = j;
					else if(qu[j].back() < qu[x].back()) x = j;
				}
				if(x) p[s[i]] = x;
				else if(!siz(nul)) p[s[i]] = p[s[w[1]]];
				else p[s[i]] = *nul.begin();
				add(p[s[i]], q[i]);
			}
			else {
				int n = p[s[i]];
//				cout << i << ' ' << n << ' ' << s[i] << ' ' << qu[3].back() << endl;
//				cout << q[1] << endl;
//				cout << siz(qu[n]) << endl;
				if(qu[n].back() == i) {
					ans.PB((pii) {1, n});
					delr(n);
				}
				else {
					assert(qu[n].front() == i && siz(nul));
					dell(n);
					int m = *nul.begin();
					ans.PB((pii) {1, m});
					ans.PB((pii) {2, m, n});
				}
			}
		}
		cout << siz(ans) << '\n';
		for(pii x : ans) {
			if(x.x == 1) cout << x.x << ' ' << x.y << '\n';
			else cout << x.x << ' ' << x.y << ' ' << x.z << '\n';
		}
	}
	return 0;
}