#include #include #include #define N (50) #define M_PI (3.141592653589793) using namespace std; struct point_t { int x, y, index; }; double arctan(double y, double x, double theta) { double phi = atan2(y, x) - theta; return (phi < 0.0) ? phi + 2.0 * M_PI : phi; } int dist(int x1, int y1, int x2, int y2) { return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); } void actual_main(void) { point_t p[N]; int n; cin >> n; int m = 0; for(int i = 0; i < n; i++) { cin >> p[i].index >> p[i].x >> p[i].y; if(p[i].y < p[m].y) m = i; } cout << n; double theta = 0.0; int x = 0; int y = p[m].y; for(int i = 0; i < n; i++) { int pos = -1; double minphi = 2.0 * M_PI; for(int j = 0; j < n; j++) { if(p[j].index < 0) continue; double phi = arctan(p[j].y - y, p[j].x - x, theta); if(phi < minphi) { pos = j; minphi = phi; } if(phi == minphi) { int d1 = dist(x, y, p[j].x, p[j].y); int d2 = dist(x, y, p[pos].x, p[pos].y); if(d1 < d2) pos = j; minphi = phi; } } theta += minphi; if(theta >= 2.0 * M_PI) theta -= 2.0 * M_PI; cout << " " << p[pos].index; p[pos].index = -1; x = p[pos].x; y = p[pos].y; } } int main(void) { int n; cin >> n; for(int i = 0; i < n; i++) actual_main(); return 0; }