#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int>> segs(n);
  vector<pair<int, pair<int, int>>> par1;
  vector<int> par;
  for (long long i = 0; i < n; i++) {
    cin >> segs[i].first >> segs[i].second;
    segs[i].second++;
    par1.push_back({segs[i].first, {1, i}});
    par1.push_back({segs[i].second, {0, i}});
  }
  sort(par1.begin(), par1.end());
  vector<pair<int, int>> toind(n);
  int prv = -1e9 - 5, cnt = 0, prvsgn = -1;
  for (auto ii : par1) {
    if (ii.first != prv || ii.second.first != prvsgn) {
      if (prv != -1e9 - 5) par.push_back(prvsgn == 1 ? cnt : -cnt);
      cnt = 0;
    }
    cnt++;
    prv = ii.first;
    prvsgn = ii.second.first;
    if (ii.second.first)
      toind[ii.second.second].first = par.size();
    else
      toind[ii.second.second].second = par.size();
  }
  if (prv != -1e9 - 5) par.push_back(prvsgn == 1 ? cnt : -cnt);
  vector<int> pre(2 * n, 0), pre1(2 * n, 0);
  cnt = 0;
  int m = par.size();
  for (long long i = 0; i < m; i++)
    pre[i] = (i ? pre[i - 1] : 0) + par[i], cnt += (pre[i] == 0);
  for (long long i = 0; i < m; i++)
    pre1[i] = (i ? pre1[i - 1] : 0) + (pre[i] == 1 ? 1 : 0);
  int bst = 0;
  for (long long i = 0; i < n; i++) {
    int l = toind[i].first + 1, r = toind[i].second - 1;
    if (l > r) bst = max(bst, cnt - 1);
    int tot = (pre1[r] - (l ? pre1[l - 1] : 0)) -
              (pre[r + 1] == 0 && par[r + 1] == -1);
    bst = max(bst, tot + cnt);
  }
  cout << bst << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
