#include #include using namespace std; struct node { int x, y; }; int cmp (const void *a, const void *b) { node *c = (node *)a; node *d = (node *)b; if (c -> x != d -> x) return c -> x - d -> x; else return d -> y - c -> y; } int main () { node stu[21000]; int t, n, i, j, k, a[21000]; cin >> t; while (t--) { memset (a, 0, sizeof(a)); cin >> n; for (i=0; i> stu[i].x >> stu[i].y; qsort (stu, n, sizeof (stu[0]), cmp); a[0] = stu[0].y, k = 1; for (i=1; i