#include #include #include #include using namespace std; #define EPS FLT_EPSILON #define deq( a, b ) (fabs((a) - (b)) < EPS) class Point { public: int pid; double x, y; Point() {} Point( int pid, double x, double y ) : pid(pid), x(x), y(y) {} double angle() const { return atan2(y, x); } double dist() const { return sqrt(x*x+y*y); } void rotate( double rad ) { const double tx = x, ty = y; x = tx*cos(rad) - ty*sin(rad); y = tx*sin(rad) + ty*cos(rad); } }; void adjust( Point &base, double rad, vector &ps ) { for ( int i = 0; i < ps.size(); i++ ) { ps[i].x = ps[i].x - base.x; ps[i].y = ps[i].y - base.y; ps[i].rotate(-rad); } } int main() { int ntest; cin >> ntest; for ( int nt = 0; nt < ntest; nt++ ) { vector ps; int npoint; cin >> npoint; ps.resize(npoint); for ( int i = 0; i < npoint; i++ ) cin >> ps[i].pid >> ps[i].x >> ps[i].y; double yA = ps[0].y; for ( int i = 0; i < ps.size(); i++ ) if ( yA > ps[i].y ) yA = ps[i].y; Point base(0, 0, yA); double rad = 0.0; cout << npoint; while ( !ps.empty() ) { adjust(base, rad, ps); int next = 0; for ( int i = 0; i < ps.size(); i++ ) if ( ps[i].angle() < ps[next].angle() ) next = i; else if ( deq(ps[i].angle(), ps[next].angle()) && ps[i].dist() < ps[next].dist() ) next = i; cout << ' ' << ps[next].pid; base = ps[next]; rad = ps[next].angle(); ps[next] = ps.back(), ps.pop_back(); } cout << endl; } return 0; }