#include <iostream>
using namespace std;
int t,n,k,m,i,j;
int lef[100002],righ[100002],cost[100002],a[100002],total=0;
int swap(int *a, int *b)
{
	int temp=*a;
	*a=*b;
	*b=temp;
}
int pivot(int l, int h)
{
	int x=cost[h],i=l,j=l-1,temp;
	for(i=l;i<h;i++)
	{
		if(cost[i]<x)
		{
			j++;
			swap(&cost[i],&cost[j]);
			swap(&righ[i],&righ[j]);
			swap(&lef[i],&lef[j]);
		}
	}
	j++;
	swap(&cost[h],&cost[j]);
	swap(&lef[h],&lef[j]);
	swap(&righ[h],&righ[j]);
	return j;
}
int quick(int l, int h)
{
	 int p;
	if(l<h)
	{
		p=pivot(l,h);
		quick(l,p-1);
		quick(p+1,h);
	}
}
int main() {
	cin>>t;
	while(t--)
	{
	    total=0;
	    cin>>n>>k>>m;
	    for(i=1;i<=n;i++)
	    {
	        cin>>a[i];
	        total+=a[i];
	    }
	    for(i=1;i<=m;i++)
	        cin>>lef[i]>>righ[i]>>cost[i];
	    quick(1,m);
	   for(i=1;i<=m;i++)
	        cout<<lef[i]<<righ[i]<<cost[i]<<endl;
	}
	return 0;
}
