#include<bits/stdc++.h>
using namespace std;
int T,n,m,k,a[2000010],op[4000010],ans1[4000010],ans2[4000010],cnt=0;
deque<int>q[1000010],uwu[10];
void st1(int x){
	cnt++,op[cnt]=1,ans1[cnt]=x;
}
void st2(int x,int y){
	cnt++;op[cnt]=2,ans1[cnt]=x,ans2[cnt]=y;
}
void solve1(int x){
	for(int i=0;i<(1<<4);i++){
		uwu[1]=q[1],uwu[2]=q[2];
		for(int j=0;j<4;j++){
			if(i&(1<<j)){
				if(!uwu[1].empty()&&uwu[1].back()==a[x+j]){
					uwu[1].pop_back();
				}
				else uwu[1].push_back(a[x+j]);
			}
			else{
				if(!uwu[2].empty()&&uwu[2].back()==a[x+j]){
					uwu[2].pop_back();
				}
				else uwu[2].push_back(a[x+j]);
			}
		}
		if((uwu[1].size()==1&&uwu[2].size()==1)||(uwu[1].size()==0&&uwu[2].size()==0)){
			for(int j=0;j<4;j++){
				if(i&(1<<j))st1(1);
				else st1(2);
			}
			q[1]=uwu[1],q[2]=uwu[2];
			return ;
		}
	}
	printf("-1\n");
	exit(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(k==2*n-2){
			for(int i=1;i<=m;i++){
				int now=(a[i]+1)/2;
				if(q[now].empty()){
					cnt++;
					op[cnt]=1;
					ans1[cnt]=now;
					q[now].push_back(a[i]);
					continue;
				}
				if(a[i]==q[now].back()){
					cnt++;
					op[cnt]=1;
					ans1[cnt]=now;
					q[now].pop_back();
					continue;
				}
				if(a[i]==q[now].front()){
					cnt++;
					op[cnt]=1;
					ans1[cnt]=n;
					cnt++;
					op[cnt]=2;
					ans1[cnt]=1,ans2[cnt]=n;
					q[now].pop_front();
					continue;
				}
				cnt++;
				op[cnt]=1;
				ans1[cnt]=now;
				q[now].push_back(a[i]);
			}
			printf("%d\n",cnt);
			for(int i=1;i<=cnt;i++){
				if(op[i]==1)printf("1 %d\n",ans1[i]);
				else printf("2 %d %d\n",ans1[i],ans2[i]);
			}
		}
		else{
			if(n==2){
				for(int i=1;i<=m;i+=4)solve1(i);
				if(q[1].size()==1&&q[2].size()==1)st2(1,2);
				printf("%d\n",cnt);
			    for(int i=1;i<=cnt;i++){
				    if(op[i]==1)printf("1 %d\n",ans1[i]);
				    else printf("2 %d %d\n",ans1[i],ans2[i]);
			    }
			}
		}
	}
}