#include<bits/stdc++.h>
#define For(i,x,y) for (int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (int i=(x);i<(y);i++)
#define Dow(i,x,y) for (int i=(x);i>=(y);i--)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define fil(a,b) memset(a,b,sizeof a)
#define all(x) x.begin(),x.end()
#define siz(x) ((int)x.size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
	ll x=0,f=1;char c=getchar();
	while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
	if (c=='-') f=-1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}

const int M = 2e6+10, K = 1e3+10;
int n,m,k,a[M],las[K],vis[K],pos[K],top[K],stk[K][5];
bool flag[M];
struct node{
	int op,x,y;
};
inline void solve(){
	n=read(),m=read(),k=read();
	set<int>s1,s2;//s1 top=0 s2 top=1
	For(i,1,m) a[i]=read(),flag[i]=0;
	For(i,1,k) las[i]=0,vis[i]=0;
	int cnt=0;
	For(i,1,m){
		vis[a[i]]^=1;
		if (vis[a[i]]) ++cnt;
			else --cnt;
		if (cnt==k) flag[las[a[i+1]]]=1;
		las[a[i]]=i;	
	}
	For(i,1,n) s1.insert(i);
	For(i,1,k) pos[i]=0;
	vector<node>ans;
	For(i,1,n) top[i]=0;
	For(i,1,m){
		int x=a[i];
		if (!flag[i]){
			if (pos[x]){
				int y=pos[x];
				if (stk[y][top[y]]==x){
					ans.pb((node){1,y,0});
					--top[y];
				} else {
				//	assert(!s1.empty());
				//	assert(top[y]==2);
					int z=*s1.begin();
					ans.pb((node){1,z,0});
					ans.pb((node){2,z,y});
					--top[y];
					stk[y][1]=stk[y][2];
				}
				if (top[y]==1) s2.insert(y);
				else if (top[y]==0){
					if (s2.count(y)) s2.erase(y);
					s1.insert(y);
				}
				pos[x]=0;
			} else {
				if (!s2.empty()){
					pos[x]=*s2.begin();
					s2.erase(pos[x]);
				} else {
					pos[x]=*s1.begin();
					s1.erase(pos[x]);
					s2.insert(pos[x]);
				}
				ans.pb((node){1,pos[x],0});
				stk[pos[x]][++top[pos[x]]]=x;
			}
		} else {
			if (!s1.empty()){
				pos[x]=*s1.begin();
				s1.erase(pos[x]);
			} else {
				pos[x]=*s2.begin();
				s2.erase(pos[x]);
			}
			ans.pb((node){1,pos[x],0});
			stk[pos[x]][++top[pos[x]]]=x;
		}
	}
	//For(i,1,n) assert(!top[i]);
	printf("%d\n",siz(ans));
	for (auto i:ans){
		if (i.op==1) printf("%d %d\n",i.op,i.x);
			else printf("%d %d %d\n",i.op,i.x,i.y);
	}
}

int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	int T=read();
	while (T--) solve();
}
/*
1
3 10 5
1 2 3 4 5 2 3 4 5 1

1
3 12 5
2 3 1 4 2 5 2 1 2 3 4 5
*/
