#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const long long INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = 3.14159265;
const long long MOD = 1e9 + 7;
template <typename T>
inline T read() {
  T X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}
const int MAXN = 200005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
struct Point {
  int x, id;
  bool end;
  bool operator<(const Point& other) const {
    return x < other.x || (x == other.x && end < other.end);
  }
};
int cov[MAXN];
void solve() {
  vector<Point> invs;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    invs.push_back({l, i, false});
    invs.push_back({r, i, true});
    cov[i] = 0;
  }
  sort(invs.begin(), invs.end());
  set<int> covered;
  int seg = 0;
  for (const auto& v : invs) {
    if (!v.end) {
      if (covered.empty()) --cov[v.id];
      covered.insert(v.id);
    } else {
      covered.erase(v.id);
      if (covered.empty()) --cov[v.id];
    }
    if (covered.empty()) seg++;
    if (covered.size() == 1) ++cov[*covered.begin()];
  }
  int ans = -INF2;
  for (int i = 0; i < n; i++) ans = max(ans, cov[i]);
  printf("%d\n", seg + ans);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}
