#include <bits/stdc++.h>
#define ll long long
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<pair<int,int>> segments(n);
    vector<int> l;
    vector<int> r;

    for (int i = 0; i < n; ++i)
    {
        cin >> segments[i].first >> segments[i].second;
        l.push_back(segments[i].first);
        r.push_back(segments[i].second);
    }

    sort(l.begin(), l.end());
    sort(r.begin(), r.end());

    int answer = n;
    for (int i = 0; i < n; ++i)
    {
        int cntBefore = lower_bound(r.begin(), r.end(), segments[i].first) - r.begin();
        int cntNext = n - (lower_bound(l.begin(), l.end(), segments[i].second + 1) - l.begin());

        answer = min(answer, cntBefore + cntNext);
    }
    cout << answer << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false),cin.tie(0);
    int tests;
    cin >> tests;
    while (tests-- > 0)
        solve();
    return 0;
}
