constint maxn = 100010; structseg { int l, r; booloperator < (const seg& rhs) const { return l < rhs.l; } } a[maxn]; int path[maxn];
intmain(){ int t; scanf("%d", &t); while (t--) { int m, n = 0; scanf("%d", &m); for (;;) { scanf("%d%d", &a[n].l, &a[n].r); if (!a[n].l && !a[n].r) { break; } ++n; } sort(a, a + n); int l = 0, r = 0, ans = 0; for (int i = 0; i < n; ) { if (a[i].l <= l) { if (a[i].r > r) { path[ans] = i; r = a[i].r; if (r >= m) { ++ans; break; } } ++i; } else { if (r <= l) { ans = 0; break; } l = r; ++ans; } } ans = r < m ? 0 : ans; printf("%d\n", ans); for (int i = 0; i < ans; ++i) { printf("%d %d\n", a[path[i]].l, a[path[i]].r); } if (t) { puts(""); } } return0; }