#include<iostream>
#include<iterator>
#include<set>
using namespace std;
class Rect
{
private:
int no;
int width;
int height;
public:
Rect(int n=0,int w=0,int h=0);
//定义为友元函数的原因是因为只有友元函数与成员函数才能访问类的私有成员
friend bool operator<(const Rect &a,const Rect &b);//运算符重载,用于排序
friend istream& operator>>(istream &is,Rect &r);//输入一个对象
friend ostream& operator<<(ostream &os,const Rect& r);//输出一个对象
};
int main()
{
set<Rect> SR;
int m,n;
cin>>m;
while(m--)
{
SR.clear();
Rect R;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>R;
SR.insert(R);
}
cout<<endl;
copy(SR.begin(),SR.end(),ostream_iterator<Rect>(cout,"\n"));
}
return 0;
}
Rect::Rect(int n,int w,int h)
{
no=n;
width=w;
height=h;
}
bool operator<(const Rect &a,const Rect &b)//注意友元函数不是类的成员,所以不能使用::限定符
{
return a.no<b.no||(a.no==b.no&&a.height<b.height)||(a.no==b.no&&a.height==b.height&&a.width<b.width);
}
istream& operator>>(istream &is,Rect& r)
{
is>>r.no>>r.height>>r.width;
if(r.height<r.width)
{
int temp=r.height;
r.height=r.width;
r.width=temp;
}
return is;
}
ostream& operator<<(ostream &os,const Rect& r)
{
os<<r.no<<" "<<r.height<<" "<<r.width;
return os;
}