#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int x = 0, f = 1;
  register char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
  return x * f;
}
inline int Mul(int a, int b) { return 1ll * a * b % 1000000007; }
inline int Inc(int a, int b) {
  return (a += b) >= 1000000007 ? a - 1000000007 : a;
}
inline int Dec(int a, int b) { return (a -= b) < 0 ? a + 1000000007 : a; }
inline int qpow(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1) r = Mul(r, a);
    a = Mul(a, a), b >>= 1;
  }
  return r;
}
int n, m, tag[200005 << 4], mi[200005 << 4], t1[200005 << 4], sum[200005 << 4],
    Ans, ans[200005 << 4], a[200005 << 1];
struct segment {
  int l, r;
} e[200005];
inline void pushup(int k) {
  sum[k] = sum[k * 2] + sum[k * 2 + 1];
  if (mi[k * 2] < mi[k * 2 + 1]) mi[k] = mi[k * 2], ans[k] = ans[k * 2];
  if (mi[k * 2 + 1] < mi[k * 2]) mi[k] = mi[k * 2 + 1], ans[k] = ans[k * 2 + 1];
  if (mi[k * 2] == mi[k * 2 + 1])
    mi[k] = mi[k * 2], ans[k] = ans[k * 2] + ans[k * 2 + 1];
}
inline void pushdown(int k, int l, int r, int mid) {
  mi[k * 2] += tag[k], mi[k * 2 + 1] += tag[k], tag[k * 2] += tag[k],
      tag[k * 2 + 1] += tag[k], tag[k] = 0;
  sum[k * 2] += (mid - l + 1) * t1[k], sum[k * 2 + 1] += (r - mid) * t1[k];
  t1[k * 2] += t1[k], t1[k * 2 + 1] += t1[k], t1[k] = 0;
}
inline void build(int k, int l, int r) {
  tag[k] = t1[k] = 0;
  if (l == r) return (void)(sum[k] = mi[k] = 0, ans[k] = 1);
  int mid = (l + r) >> 1;
  build(k * 2, l, mid), build(k * 2 + 1, mid + 1, r), pushup(k);
}
inline void modify(int k, int l, int r, int ll, int rr, int v) {
  if (ll <= l && r <= rr) return (void)(mi[k] += v, tag[k] += v);
  int mid = (l + r) >> 1;
  pushdown(k, l, r, mid);
  if (ll <= mid) modify(k * 2, l, mid, ll, rr, v);
  if (mid < rr) modify(k * 2 + 1, mid + 1, r, ll, rr, v);
  pushup(k);
}
inline void Modify(int k, int l, int r, int ll, int rr, int v) {
  if (ll <= l && r <= rr) return (void)(sum[k] += (r - l + 1) * v, t1[k] += v);
  int mid = (l + r) >> 1;
  pushdown(k, l, r, mid);
  if (ll <= mid) Modify(k * 2, l, mid, ll, rr, v);
  if (mid < rr) Modify(k * 2 + 1, mid + 1, r, ll, rr, v);
  pushup(k);
}
inline int query(int k, int l, int r, int ll) {
  if (l == r) return sum[k];
  int mid = (l + r) >> 1;
  pushdown(k, l, r, mid);
  if (ll > mid) return query(k * 2 + 1, mid + 1, r, ll);
  return query(k * 2, l, mid, ll);
}
int main() {
  int T = read();
  while (T--) {
    n = read(), Ans = 1;
    for (int i = (1), iLimit = (n); i <= iLimit; ++i)
      a[i * 2 - 1] = e[i].l = read(), a[i * 2] = e[i].r = read();
    sort(a + 1, a + 2 * n + 1);
    int N = unique(a + 1, a + 2 * n + 1) - a - 1;
    build(1, 1, N);
    for (int i = (1), iLimit = (n); i <= iLimit; ++i)
      e[i].l = lower_bound(a + 1, a + N + 1, e[i].l) - a;
    for (int i = (1), iLimit = (n); i <= iLimit; ++i)
      e[i].r = lower_bound(a + 1, a + N + 1, e[i].r) - a;
    for (int i = (1), iLimit = (n); i <= iLimit; ++i)
      modify(1, 1, N, e[i].l, N, 1), modify(1, 1, N, e[i].r, N, -1);
    for (int i = (1), iLimit = (n); i <= iLimit; ++i)
      Modify(1, 1, N, e[i].l, e[i].r, 1);
    for (int i = (1), iLimit = (n); i <= iLimit; ++i) {
      modify(1, 1, N, e[i].l, N, -1), modify(1, 1, N, e[i].r, N, 1);
      Modify(1, 1, N, e[i].l, e[i].r, -1);
      int pax = ans[1];
      if (query(1, 1, N, e[i].l) == 0) --pax;
      if (e[i].l != e[i].r && query(1, 1, N, e[i].r) == 0) --pax;
      Ans = max(Ans, pax);
      modify(1, 1, N, e[i].l, N, 1), modify(1, 1, N, e[i].r, N, -1);
      Modify(1, 1, N, e[i].l, e[i].r, 1);
    }
    printf("%d\n", Ans);
  }
  return 0;
}
