#include<bits/stdc++.h>
using namespace std;

struct node{
	int a,b,c;
};

deque<int> q[305];
queue<node> qq;
long long m,ans;
int n,k,qn[305],T;

int main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	cin>>T;
	while(T--){
		ans=0;
		memset(qn,0,sizeof(qn));
		cin>>n>>m>>k;
		while(!qq.empty()) qq.pop();
		for(int i=1 ;i<=n ;i++)
			while(!q[i].empty()) q[i].pop_back();
		while(m--){
			int flag=1,e=0,a;
			cin>>a;
			for(int i=1 ;i<=n ;i++)
				if(q[i].empty()){
					e=i;
					break;
				}
			for(int i=1 ;i<=n ;i++){
				//if(!q[i].empty()) cout<<q[i].front()<<' '<<q[i].back()<<' '<<e<<' '<<a<<endl;
				if(!q[i].empty() and q[i].back()==a){
					q[i].pop_back();
					qn[i]--;
					flag=0;
					qq.push((node){1,i,0});
					ans++;
					break;
				}
				if(!q[i].empty() and (q[i].front()==a and e)){
					q[i].pop_front();
					qn[i]--;
					flag=0;
					qq.push((node){1,i,0});
					qq.push((node){2,i,e});
					ans+=2;
					break;
				}
			}
			int iss=1;
			if(flag){
				for(int i=1 ;i<=n-1 ;i++){
					if(qn[i] < n/2){
						q[i].push_back(a);
						qn[i]++;
						qq.push((node){1,i,0});
						ans++;
						iss=0;
						break;
					}
				}
			}
			if(iss){
				q[1].push_back(a);
				qn[1]++;
				qq.push((node){1,1,0});
				ans++;
			}
		}
		cout<<ans<<endl;
		while(!qq.empty()){
			if(qq.front().a==1) cout<<qq.front().a<<' '<<qq.front().b<<endl;
			if(qq.front().a==2) cout<<qq.front().a<<' '<<qq.front().b<<' '<<qq.front().c<<endl;
			qq.pop();
		}
	}
	return 0;
}
