#include <bits/stdc++.h>
using namespace std;
int t, n;
pair<int, int> a[((int)2e5 + 20)];
unordered_map<int, int> mem[((int)2e5 + 20)][5];
int solve(int i, int mx, int taken) {
  if (i >= n) {
    if (!taken) return -1000;
    return 1;
  }
  if (mem[i][taken].find(mx) != mem[i][taken].end()) {
    return mem[i][taken][mx];
  }
  int sum = 0;
  if (a[i].first > mx) {
    sum = 1;
  }
  if (mx < -1e9) {
    sum = 0;
  }
  int res1 = 0, res2 = 0;
  res1 = solve(i + 1, max(mx, a[i].second), taken) + sum;
  if (!taken) {
    res2 = solve(i + 1, mx, 1);
  }
  return mem[i][taken][mx] = max(res1, res2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i].first >> a[i].second;
    }
    sort(a, a + n);
    auto ans = solve(0, -1e9 - 10, 0);
    cout << ans << endl;
    for (int i = 0; i <= n; i++) {
      mem[i][0].clear();
      mem[i][1].clear();
    }
  }
  return 0;
}
