#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infll = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
const int maxn = 2e5 + 10;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    vector<pair<int, int> > a;
    int l, r;
    for (int i = 1; i <= n; ++i) {
      cin >> l >> r;
      a.push_back(pair<int, int>(l, -i));
      a.push_back(pair<int, int>(r, i));
    }
    a.push_back(pair<int, int>(inf, 0));
    sort(a.begin(), a.end());
    multiset<int> s;
    int cnt = 0;
    vector<int> ans(maxn);
    for (int i = 0; i < 2 * n; ++i) {
      if (a[i].second < 0)
        s.insert(-a[i].second);
      else if (a[i].second > 0)
        s.erase(s.find(a[i].second));
      if (s.size() == 0) cnt++;
      if (s.size() == 1 and a[i].second < 0 and a[i + 1].second > 0)
        ans[-a[i].second]--;
      if (s.size() == 1 and a[i].second > 0 and a[i + 1].second < 0 and
          a[i + 1].first > a[i].first)
        ans[*s.begin()]++;
    }
    int maxans = -1;
    for (int i = 1; i <= n; ++i) maxans = max(maxans, ans[i]);
    cout << maxans + cnt << endl;
  }
  return 0;
}
