#include<bits/stdc++.h>
using namespace std;
int const N=2000010,M=305;
int t;
namespace solve1{
	int n,m,k,a[N];
	deque<int>q[M];
	vector<array<int,3> >ans;
	void solve15pts(){
		while(t--){
			cin>>n>>m>>k;
			for(int i=1;i<=m;i++)
				cin>>a[i];
			ans.clear();
			for(int i=1;i<=n;i++)
				q[i]=deque<int>();
			for(int i=1;i<=m;i++){
				int flg=0;
				for(int j=1;j<n;j++){
					if(q[j].empty())
						continue;
					if(q[j].front()==a[i]){
						ans.push_back({1,j,0});
						q[j].pop_front();
						flg=1;
						break;
					}
					if(q[j].back()==a[i]){
						ans.push_back({1,n,0});
						ans.push_back({2,j,n});
						q[j].pop_back();
						flg=1;
						break;
					}
				}
				if(!flg){
					for(int j=1;j<n;j++)
						if(q[j].size()<2){
							ans.push_back({1,j,0});
							q[j].push_front(a[i]);
							break;
						}
				}
			}
			for(int i=1;i<=n;i++)
				assert(q[i].empty());
			cout<<ans.size()<<"\n";
			for(auto i:ans){
				cout<<i[0];
				for(int j=1;j<=i[0];j++)
					cout<<" "<<i[j];
				cout<<"\n";
			}
		}
	}
}
namespace solve3{
	int n,m,k,a[N];
	deque<int>q[M];
	mt19937 rnd(time(0));
	vector<array<int,3> >ans;
	int dfs(int i){
		if(i>m){
			int flg=1;
			for(int i=1;i<=n;i++)
				flg&=q[i].empty();
			if(flg){
				cout<<ans.size()<<"\n";
				for(auto i:ans){
					cout<<i[0];
					for(int j=1;j<=i[0];j++)
						cout<<" "<<i[j];
					cout<<"\n";
				}
				return 1;
			}
			return 0;
		}
		int p=0;
		for(int j=1;j<=n;j++)
			if(q[j].empty())
				p=j;	
		for(int j=1;j<n;j++){
			if(q[j].empty())
				continue;
			if(q[j].front()==a[i]){
				ans.push_back({1,j,0});
				q[j].pop_front();
				if(dfs(i+1))
					return 1;
				q[j].push_front(a[i]);
				ans.pop_back();
			}
			if(q[j].back()==a[i]&&p){
				ans.push_back({1,p,0});
				ans.push_back({2,j,p});
				q[j].pop_back();
				if(dfs(i+1))
					return 1;
				q[j].push_back(a[i]);
				ans.pop_back();
				ans.pop_back();
			}
		}
		vector<int>t(n);
		for(int j=0;j<n;j++)
			t[j]=j+1;
		shuffle(t.begin(),t.end(),rnd);
		for(int j:t){
			ans.push_back({1,j,0});
			q[j].push_front(a[i]);
			if(dfs(i+1))
				return 1;
			q[j].pop_front();
			ans.pop_back();
		}
		return 0;
	}
	void solve20pts(){
		while(t--){
			cin>>n>>m>>k;
			for(int i=1;i<=m;i++)
				cin>>a[i];
			for(int i=1;i<=n;i++)
				q[i]=deque<int>();
			ans.clear();
			if(!dfs(1))
				cout<<"-1\n";
		}
	}
}
int main(){
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	ios::sync_with_stdio(0);
	cin>>t;
	if(t%10==1)
		solve1::solve15pts();
	else
		solve3::solve20pts();
}
