#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e6+10;
int T;
int n,m,k;//input

int op,opt,s1,s2;//output
int a[MAXN];
int mat[MAXN];
int pos[MAXN];
int now_pos;
bool willmat[MAXN];
int nowmat;
struct node {
	int Id;
	int cl,cl2;
} tr[MAXN];
signed main() {
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	cin>>T;
	memset(willmat,false,sizeof willmat);
	cin>>n>>m>>k;
	for(int i=1; i<=m; i++) {
		cin>>a[i];
	}
	for(int i=m; i>=1; i--) {
		if(pos[a[i]]==0) {
			pos[a[i]]=i;
		} else {
			mat[i]=pos[a[i]];
			pos[a[i]]=0;
		}
	}
	int now=1;
	now_pos=0;
	int cnt=0;
	for(int i=1; i<=m; i++) {
		if(willmat[i]==true) {
			continue;
		}
		if(mat[i]>now_pos) {
			tr[i].Id=1;
			tr[i].cl=now;
			tr[mat[i]].cl=n;
			tr[mat[i]].cl2=now;
			willmat[mat[i]]=true;
			now_pos=mat[i];
		} else {
			tr[i].Id=1;
			tr[mat[i]].Id=1;
			now++;
			if(now>n) {
				now=1;
			}
			tr[i].cl=now;
			tr[mat[i]].cl=now;
			now_pos=mat[i];
		}
	}
	int ans=0;
	for(int i=1; i<=m; i++) {
		if(tr[i].Id==1) {
			ans++;
		} else {
			ans+=2;
		}
	}
	printf("%d\n", ans);
	for(int i=1; i<=m; i++) {
		if(tr[i].Id==1) {
			printf("1 %d\n", tr[i].cl);
		} else {
			printf("1 %d\n", tr[i].cl);
			printf("2 %d %d\n", tr[i].cl,tr[i].cl2);
		}
	}
	return 0;
}