#include <bits/stdc++.h>

using namespace std;

inline int read(){
	int x = 0, f = 1;
	char ch = getchar();
	while (! isdigit(ch)){
		if (ch == '-')
			f = - f;
		ch = getchar();
	}
	while (isdigit(ch)){
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	return x * f;
}

void write(int x){
	if (x < 0){
		putchar('-');
		write(- x);
		return;
	}
	if (x >= 10)
		write(x / 10);
	putchar(x % 10 + 48);
	return;
}

inline void writeln(int x){
	write(x);
	puts("");
	return;
}

inline void writesp(int x){
	write(x);
	putchar(' ');
	return;
}

const int MAXN = 505, MAXM = 2e6 + 5;

int n, m, k, T;
int a[MAXM], lst[MAXM], nxt[MAXM], bo[MAXN];
deque < int > q[MAXN];

inline void prep(){
	for (int i = 0; i <= m + 5; ++ i)
		lst[i] = nxt[i] = 0;
	for (int i = 0; i <= n + 5; ++ i){
		if (! q[i].empty())
			q[i].pop_back();
		bo[i] = 0;
	}
	return;
}

signed main(){
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	T = read();
	while (T --){
		n = read(), m = read(), k = read();
		prep();
		int opt = 0;
		for (int i = 1; i <= m; ++ i)
			a[i] = read();
		for (int i = m; i >= 1; -- i){
			nxt[i] = lst[a[i]];
			lst[a[i]] = i;
		}
		q[1].push_front(1);
		opt ++;
		for (int i = 2; i <= m; ++ i){
			bool flag = 0;
			for (int j = 1; j <= n; ++ j)
				if (! q[j].empty() && a[q[j].front()] == a[i]){
//					writesp(1), writeln(j);
					opt ++;
					q[j].pop_front();
					flag = 1;
					break;
				}
			if (flag)
				continue;
			flag = 0;
			for (int j = 1; j <= n; ++ j)
				if (! q[j].empty() && nxt[q[j].front()] > nxt[i]){
					q[j].push_front(i);
					opt ++;
//					writesp(1), writeln(j);
					flag = 1;
					break;
				}
			if (flag)
				continue;
			flag = 0;
			for (int j = 1; j <= n; ++ j)
				if (q[j].empty()){
					q[j].push_front(i);
					opt ++;
//					writesp(1), writeln(j);
					flag = 1;
					break;
				}
			if (! flag){
				q[1].push_front(i);
//				writesp(1), writeln(i);
				opt ++;
			}
			for (int j = 1; j <= k; ++ j)
				bo[j] = 0;
			for (int j = 1; j <= n; ++ j){
				if (q[j].empty())
					continue;
				if (bo[q[j].back()] == 0){
					bo[q[j].back()] == j;
					continue;
				}
				opt ++;
//				writesp(2), writesp(bo[q[j].back()]), writeln(j);
				bo[q[j].back()] = 0;
			}
		}
		for (int j = 1; j <= k; ++ j)
			bo[j] = 0;
		for (int j = 1; j <= n; ++ j){
			if (q[j].empty())
				continue;
			if (bo[q[j].back()] == 0){
				bo[q[j].back()] == j;
				continue;
			}
			opt ++;
//			writesp(2), writesp(bo[q[j].back()]), writeln(j);
			bo[q[j].back()] = 0;
		}
		writeln(opt);
		
		
		prep();
		for (int i = m; i >= 1; -- i){
			nxt[i] = lst[a[i]];
			lst[a[i]] = i;
		}
		q[1].push_front(1);
		writesp(1), writeln(1);
		for (int i = 2; i <= m; ++ i){
			bool flag = 0;
			for (int j = 1; j <= n; ++ j)
				if (! q[j].empty() && a[q[j].front()] == a[i]){
					writesp(1), writeln(j);
					opt ++;
					q[j].pop_front();
					flag = 1;
					break;
				}
			if (flag)
				continue;
			flag = 0;
			for (int j = 1; j <= n; ++ j)
				if (! q[j].empty() && nxt[q[j].front()] > nxt[i]){
					q[j].push_front(i);
					opt ++;
					writesp(1), writeln(j);
					flag = 1;
					break;
				}
			if (flag)
				continue;
			flag = 0;
			for (int j = 1; j <= n; ++ j)
				if (q[j].empty()){
					q[j].push_front(i);
					opt ++;
					writesp(1), writeln(j);
					flag = 1;
					break;
				}
			if (! flag){
				q[1].push_front(i);
				writesp(1), writeln(i);
				opt ++;
			}
			for (int j = 1; j <= k; ++ j)
				bo[j] = 0;
			for (int j = 1; j <= n; ++ j){
				if (q[j].empty())
					continue;
				if (bo[q[j].back()] == 0){
					bo[q[j].back()] == j;
					continue;
				}
				opt ++;
				writesp(2), writesp(bo[q[j].back()]), writeln(j);
				bo[q[j].back()] = 0;
			}
		}
		for (int j = 1; j <= k; ++ j)
			bo[j] = 0;
		for (int j = 1; j <= n; ++ j){
			if (q[j].empty())
				continue;
			if (bo[q[j].back()] == 0){
				bo[q[j].back()] == j;
				continue;
			}
			opt ++;
			writesp(2), writesp(bo[q[j].back()]), writeln(j);
			bo[q[j].back()] = 0;
		}
	}				
	fclose(stdin);
	fclose(stdout);
	return 0;
}
