#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <deque>

typedef long long LL;

using namespace std;

const int N = 2010000;

struct edge{
	int k, x, y;
}stk[N*2];

struct re{
	bool f;
	int x, y;
}kong[N];

int n, m, k;
int T, id;
int a[N];


bool solve(deque<int>& q, int x,int type, int& cnt){
	if(q.empty()){
		stk[cnt ++] = {1, type};
		q.push_back(x);
		return true;
	}
	else if(q.back() == x){
		stk[cnt ++] = {1,type};
		q.pop_back();
		return true;
	}
	else if(q.front() == x){
		stk[cnt ++] = {1, 3};
		stk[cnt ++] = {2, type, 3};
		q.pop_front();
		return true;
	} 
	return false;
	
}

void init(int x){
	for(int i = 1; i <= x; i ++){
		kong[i] = {0,0};
	}
}

int main(){
	
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	
	scanf("%d", &T);
	
	while(T --){
		scanf("%d%d%d", &n, &m, &k);
		for(int i = 1; i <= m; i ++){
			scanf("%d", &a[i]);
		}
		
		
		if(n == 2){
			deque<int> q;
			int cnt = 0;
			for(int i = 1; i <= m; i ++){
				
				
				if(q.empty() || q.back() != a[i] && q.front() != a[i]){
					stk[cnt++] = {1, 1};
					q.push_back(a[i]);
				}
				else if(q.back() == a[i]){
					q.pop_back();
					stk[cnt++] = {1,1};
				}
				else if(q.front() == a[i]){
					q.pop_front();
					stk[cnt++] = {1,2};
					stk[cnt++] = {2,1,2};
				}
				
			}
			
			printf("%d\n", cnt);
			for(int i = 0; i < cnt; i ++){
				if(stk[i].k == 1){
					printf("%d %d\n", stk[i].k, stk[i].x);
				}
				else{
					printf("%d %d %d\n", stk[i].k, stk[i].x, stk[i].y);
				}
			}
		}
		else if(n == 3){
			deque<int> q1, q2;
			int cnt = 0;
			for(int i = 1; i <= m; i ++){
				if(!solve(q1,a[i],1, cnt)){
					if(!solve(q2, a[i], 2, cnt)){
						if(q1.size() <= q2.size()){
							stk[cnt ++] = {1, 1};
							q1.push_back(a[i]);
							
						}
						else{
							stk[cnt ++] = {1, 2};
							q2.push_back(a[i]);
						}
					}
				}
				while(q1.front() == q2.front()){
					stk[cnt ++] = {2, 1, 2};
					q1.pop_front(), q2.pop_front();
				}
			}
			printf("%d\n", cnt);
			for(int i = 0; i < cnt; i ++){
				if(stk[i].k == 1){
					printf("%d %d\n", stk[i].k, stk[i].x);
				}
				else{
					printf("%d %d %d\n", stk[i].k, stk[i].x, stk[i].y);
				}
			}
		}
		else{
			
			int cnt = 0;
			if(n >= k){
				init(m);
				for(int i = 1; i <= m; i ++){
					stk[cnt ++] = {1, a[i]};
				}
				printf("%d\n", cnt);
				for(int i = 0; i < cnt; i ++){
					if(stk[i].k == 1){
						printf("%d %d\n", stk[i].k, stk[i].x);
					}
					else{
						printf("%d %d %d\n", stk[i].k, stk[i].x, stk[i].y);
					}
				}
			}
			else{
				
					init(n);
					for(int i = 1; i <= m; i ++){
						int t = a[i];
						if(t > n-1){
							t -= n-1;
						}
						if(!kong[t].f){
							kong[t].f = true;
							kong[t].x = a[i];
							stk[cnt ++] = {1, t}; 
						}
						else{
							if(kong[t].x != t && kong[t].y != t){
								kong[t].y = t;
								stk[cnt ++] = {1, t};
							}
							else if(kong[t].x == a[i] && kong[t].x == t && !kong[t].y){
								kong[t].x = 0;
								kong[t].f = false;
								stk[cnt ++] = {1,t};
							}
							else if(kong[t].y == a[i] &&kong[t].y == t && !kong[t].x){
								kong[t].y = 0;
								kong[t].f = false;
								stk[cnt ++] = {1, t};
							}
							
							else if(kong[t].y == a[i] && kong[t].x){
								kong[t].y = 0;
								stk[cnt ++] = {1, t};
							}
							else if(kong[t].x == a[i] && kong[t].y){
								kong[t].x == 0;
								stk[cnt ++] = {1, n};
								stk[cnt ++] = {2, t, n};
							}
							else if(kong[t].x != a[i]){
								kong[t].y = a[i];
								stk[cnt ++] = {1, t};
							}
							else if(kong[t].y != a[i] && !kong[t].x){
								
								kong[t].x = kong[t].y;
								kong[t].y = a[i];
								stk[cnt ++] = {1, t}; 
							}
						}
					}
					printf("%d\n", cnt);
					for(int i = 0; i < cnt; i ++){
					if(stk[i].k == 1){
						printf("%d %d\n", stk[i].k, stk[i].x);
					}
					else{
						printf("%d %d %d\n", stk[i].k, stk[i].x, stk[i].y);
					}
				}
				
			}
		}
		
		
	}
	
	
	return 0;
}

/*
1
2 4 2
1 2 1 2

*/