#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f * x;
}
const int maxn = 4e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n;
pair<int, int> p[maxn];
int d[maxn];
void solve() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    p[2 * i - 1].first = read();
    p[2 * i - 1].second = -i;
    p[2 * i].first = read();
    p[2 * i].second = i;
    d[i] = 0;
  }
  sort(p + 1, p + 1 + 2 * n);
  set<int> s;
  int ans = 0;
  for (int i = 1; i <= 2 * n; ++i) {
    if (p[i].second < 0)
      s.insert(-p[i].second);
    else
      s.erase(s.find(p[i].second));
    if (s.size() == 1 && p[i].second > 0 && p[i + 1].second < 0 &&
        p[i].first != p[i + 1].first)
      d[*s.begin()]++;
    else if (s.size() == 1 && p[i].second < 0 && p[i + 1].second > 0)
      d[*s.begin()]--;
    else if (s.size() == 0)
      ans++;
  }
  printf("%d\n", ans + *max_element(d + 1, d + 1 + n));
}
int main() {
  int T = read();
  while (T--) solve();
}
