#include<iostream>
#include<algorithm>
#define N 1010
using namespace std;
struct SS
{
int t1,t2,t3;
}a[N];
bool Comp(SS a,SS b)
{
if(a.t1<b.t1) return true;
if(a.t1==b.t1&&a.t2<b.t2) return true;
if(a.t1==b.t1&&a.t2==b.t2&&a.t3<=b.t3) return true;
return false;
}
int main()
{
int test;
cin>>test;
while(test--)
{
int n,i;
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i].t1>>a[i].t2>>a[i].t3;
if(a[i].t2<a[i].t3) swap(a[i].t2,a[i].t3);
}
sort(a,a+n,Comp);
cout<<a[0].t1<<" "<<a[0].t2<<" "<<a[0].t3<<endl;
for(i=1;i<n;i++)
{
if(a[i].t1==a[i-1].t1&&a[i].t2==a[i-1].t2&&a[i].t3==a[i-1].t3)
continue;
cout<<a[i].t1<<" "<<a[i].t2<<" "<<a[i].t3<<endl;
}
}
return 0;
}