#include <bits/stdc++.h>
using namespace std;
int inf = 2e9;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
map<int, int> tab;
int getan(vector<pair<int, int> > a) {
  int cnt = 0;
  int l = -inf, r = -inf;
  sort(a.begin(), a.end());
  for (int i = 0; i < a.size(); i++) {
    if (a[i].first > r) {
      if (r != -inf) tab[l] = 0;
      l = a[i].first, r = a[i].second;
      cnt++;
    } else {
      r = max(r, a[i].second);
    }
  }
  tab[l] = 0;
  return cnt;
}
void fun(vector<pair<int, pair<int, int> > > a, vector<int> &ans) {
  set<int> an;
  for (int i = 0; i < a.size(); i++) {
    vector<int> o, e;
    int j = i - 1;
    while (j + 1 < a.size() && a[j + 1].first == a[i].first) {
      ++j;
      if (a[j].second.second == 1)
        o.push_back(a[j].second.first);
      else
        e.push_back(a[j].second.first);
    }
    if (an.size() == 1 && !o.empty()) {
      ans[*an.begin()]++;
    }
    for (int k = 0; k < o.size(); k++) {
      an.insert(o[k]);
    }
    for (int k = 0; k < e.size(); k++) {
      an.erase(e[k]);
    }
    i = j;
  }
}
void solve() {
  tab.clear();
  int k;
  cin >> k;
  vector<pair<int, int> > p(k);
  vector<pair<int, pair<int, int> > > f;
  vector<int> ans(k, 0);
  for (int i = 0; i < k; i++) {
    cin >> p[i].first >> p[i].second;
  }
  for (int i = 0; i < k; i++) {
    f.push_back(make_pair(p[i].first, make_pair(i, 1)));
    f.push_back(make_pair(p[i].second, make_pair(i, -1)));
  }
  sort(f.begin(), f.end());
  int cur = getan(p);
  fun(f, ans);
  for (int i = 0; i < k; i++)
    if (tab.count(p[i].first)) tab[p[i].first]++;
  for (int i = 0; i < k; i++)
    if (tab[p[i].first] == 1) ans[i]--;
  cout << cur + (*max_element(ans.begin(), ans.end())) << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) solve();
  return 0;
}
