#include <bits/stdc++.h>
using namespace std;

#define int long long
#define mod 1000000007
#define pb push_back
#define S second
#define F first
#define inf 1e18
#define all(v) v.begin(), v.end()

#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n" \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)

int32_t main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  w(tt) {
    int n;
    cin >> n;
    vector<pair<int,int>> v(n);
    for(auto &i: v)
      cin >> i.F >> i.S;
    vector<int> left,right;
    for(auto i: v) {
      left.pb(i.S);
      right.pb(i.F);
    }
    sort(all(left));
    sort(all(right));
    int ans = n;
    for(int i = 0; i < n; ++i) {
      int it = upper_bound(all(right),v[i].S) - right.begin();
      int it2 = lower_bound(all(left),v[i].F) - left.begin();
      it = n - it;

      if(it2 == n) continue;
      if(left[it2] >= v[i].F)
        it2--;
      ans = min(ans,it + it2 + 1);
      //deb2(it,it2);
    }
    cout << ans << "\n";
  }
  return 0;
}
