#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
pair<int, int> a[maxn << 1];
int add[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      add[i] = 0;
      int x, y;
      cin >> x >> y;
      a[2 * i - 1] = make_pair(x, -i);
      a[2 * i] = make_pair(y, i);
    }
    sort(a + 1, a + 1 + 2 * n);
    multiset<int> st;
    int ans1 = 0, ans2 = 0;
    for (int i = 1; i <= 2 * n; i++) {
      if (a[i].second < 0)
        st.insert(-a[i].second);
      else
        st.erase(st.find(a[i].second));
      if (st.size() == 0) ans1++;
      if (st.size() == 1 && a[i].second > 0 && a[i + 1].second < 0 &&
          a[i].first < a[i + 1].first)
        add[*st.begin()]++;
      if (st.size() == 1 && a[i].second < 0 && a[i + 1].second > 0)
        add[*st.begin()]--;
    }
    ans2 = -1000000007;
    for (int i = 1; i <= n; i++) {
      ans2 = max(ans2, add[i]);
    }
    cout << ans1 + ans2 << '\n';
  }
}
