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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        int N;
        cin >> N;
        vector<pair<ll,ll>> mons(N);
        for (int i = 0; i < N; i++) {
            cin >> mons[i].first >> mons[i].second; // {A, B}
        }

        // Sort by endurance B ascending
        sort(mons.begin(), mons.end(),
             [](auto &m1, auto &m2){
                 return m1.second < m2.second;
             });

        priority_queue<ll> pq; // max-heap of powers A
        ll sumA = 0;
        int best = 0;

        for (auto &m : mons) {
            ll A = m.first;
            ll B = m.second;
            // include this monster
            sumA += A;
            pq.push(A);
            // if average power > B, drop the monster with largest A
            while (!pq.empty() && sumA > (ll)pq.size() * B) {
                sumA -= pq.top();
                pq.pop();
            }
            best = max(best, (int)pq.size());
        }

        cout << best << "\n";
    }

    return 0;
}
