#include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<int, int>>> qry;
vector<pair<int, int>> p;
map<int, int> l;
vector<int> ans;
int union_set() {
  int s = p[0].first, e = p[0].second, ret = 1;
  l[s] = 0;
  for (int i = 1; i < p.size(); ++i) {
    if (p[i].first > e) l[p[i].first] = 0, ret++;
    e = max(e, p[i].second);
  }
  return ret;
}
void calc_union() {
  set<pair<int, int>> s;
  sort(qry.begin(), qry.end());
  for (int i = 0; i < qry.size() - 1; ++i) {
    int j = i;
    while (qry[j].second.first == 0 && qry[j].first == qry[i].first) {
      int idx = qry[j++].second.second;
      s.erase({p[idx].first, idx});
    }
    if (s.size() == 1 && qry[i].first == qry[j].first)
      ans[(*s.begin()).second]++;
    while (qry[j].first == qry[i].first)
      s.insert({qry[j].first, qry[j++].second.second});
    i = j - 1;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    l.clear();
    p.resize(n);
    ans.assign(n, 0);
    qry.clear();
    for (int i = 0; i < n; ++i) cin >> p[i].first >> p[i].second;
    sort(p.begin(), p.end());
    for (int i = 0; i < n; ++i) {
      qry.push_back({p[i].first, {1, i}});
      qry.push_back({p[i].second + 1, {0, i}});
    }
    qry.push_back({1e9 + 5, {5, -1}});
    int init = union_set(), nf = INT_MIN;
    calc_union();
    for (int i = 0; i < n; ++i)
      if (l.count(p[i].first)) l[p[i].first]++;
    for (int i = 0; i < n; ++i) {
      if (l[p[i].first] == 1) ans[i]--;
      nf = max(ans[i], nf);
    }
    cout << init + nf << '\n';
  }
}
