func_code_string: #include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   struct Event {     long long x, t, i;     Event() {}     Event(long long x, long long t, long long i) : x(x), t(t), i(i) {}   };   bool cmpEvents(const Event &a, const Event &b) {     return tie(a.x, a.t, a.i) < tie(b.x, b.t, b.i);   }   const long long MAX_N = 2e5 + 5;   long long n;   long long cnt[MAX_N];   pair<bool, bool> cover[MAX_N];   void solve() {     cin >> n;     vector<Event> sc;     for (long long i = 1; i <= n; ++i) {       cnt[i] = 0;       cover[i] = make_pair(false, false);       long long l, r;       cin >> l >> r;       l *= 2, r *= 2;       sc.emplace_back(l, -1, i);       sc.emplace_back(r, 1, i);     }     sort(sc.begin(), sc.end(), cmpEvents);     for (long long i = 1; i < 2 * n; ++i) {       sc.emplace_back((sc[i - 1].x + sc[i].x) / 2, 0, 0);     }     sort(sc.begin(), sc.end(), cmpEvents);     set<long long> alive;     long long start_ans = 2;     for (long long i = 0; i < (long long)sc.size();) {       long long j = i;       while (j < (long long)sc.size() && sc[i].x == sc[j].x && sc[j].t == -1) {         alive.emplace(sc[j].i);         ++j;       }       while (i < j) {         cover[sc[i].i].first = (long long)alive.size() > 1;         ++i;       }       while (j < (long long)sc.size() && sc[i].x == sc[j].x && sc[j].t == 0) {         if ((long long)alive.size() == 1) {           cnt[*alive.begin()]++;         }         ++j;       }       if (alive.empty()) {         start_ans++;       }       i = j;       while (j < (long long)sc.size() && sc[i].x == sc[j].x && sc[j].t == 1) {         cover[sc[j].i].second = (long long)alive.size() > 1;         ++j;       }       while (i < j) {         alive.erase(sc[i].i);         ++i;       }     }     long long ans = 0;     for (long long i = 1; i <= n; ++i) {       ans = max(ans, start_ans + cnt[i] - !cover[i].first - !cover[i].second - 1);     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long T;     cin >> T;     while (T--) {       solve();     }     return 0;   }   