#include <bits/stdc++.h>
using namespace std;
int l[200002], r[200002], add[200002];
pair<int, int> p[200002];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, ans = 0, sum = 0;
    scanf("%d", &n);
    vector<int> v;
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &l[i], &r[i]);
      v.emplace_back(l[i]);
      v.emplace_back(r[i]);
      p[i] = pair<int, int>(l[i], r[i]);
      add[i] = 0;
    }
    sort(p + 1, p + 1 + n);
    for (int i = 1; i <= n; i++) l[i] = p[i].first, r[i] = p[i].second;
    multiset<pair<int, int> > seg;
    multiset<int> mx;
    for (int i = 1; i <= n; i++) {
      while (!seg.empty() && seg.begin()->first < l[i]) seg.erase(seg.begin());
      if (seg.empty())
        sum++;
      else if (seg.size() == 1) {
        int idx = seg.begin()->second;
        int en = *mx.rbegin();
        mx.erase(--mx.end());
        if (!mx.empty() && *mx.rbegin() >= l[idx]) add[idx]++;
        mx.insert(en);
      }
      if ((i == n || l[i + 1] > r[i]) && seg.empty()) add[i]--;
      seg.insert(pair<int, int>(r[i], i));
      mx.insert(r[i]);
    }
    for (int i = 1; i <= n; i++) ans = max(ans, sum + add[i]);
    printf("%d\n", ans);
  }
}
