#include using namespace std; const int MaxN = (int)4e5 + 10; const int MOD = (int)1e9 + 7; const int INF = 1e9; int n; pair < int, int > f[MaxN]; int c[1 << 20], sz; long long t[1 << 20]; void upd(int r, int val) { r += sz; t[r] += val; c[r] += 1; while (r > 1) { t[r >> 1] = t[r] + t[r ^ 1]; c[r >> 1] = c[r] + c[r ^ 1]; r >>= 1; } } void solve() { scanf("%d", &n); // k * min(a1, a2, ..., ai) >= b1 + ... + bi vector < pair < int, int > > idx(n); for (int i = 0; i < n; ++i) { scanf("%d%d", &f[i].first, &f[i].second); } sort(f, f + n); for (int i = 0; i < n; ++i) { idx[i] = make_pair(f[i].second, i); } sz = 1; while (sz < n) { sz *= 2; } sort(idx.begin(), idx.end()); for (int i = 0; i < 2 * sz; ++i) { t[i] = c[i] = 0; } int ans = 0; for (int i = n - 1; i >= 0; --i) { if (f[i].first >= f[i].second) { ans = max(ans, 1); } long long cur = f[i].second; int now = 1, root = 1; while (root < sz) { if ((t[root] + cur) <= 1LL * (c[root] + now) * f[i].first) { now += c[root]; ans = max(ans, now); break; } root <<= 1; if ((t[root] + cur) <= 1LL * (c[root] + now) * f[i].first) { now += c[root]; cur += t[root]; ans = max(ans, now); root |= 1; } } int where = lower_bound(idx.begin(), idx.end(), make_pair(f[i].second, i)) - idx.begin(); upd(where, +f[i].second); } printf("%d\n", ans); } int main() { // freopen("input.txt", "r", stdin); int t; scanf("%d", &t); while (t --> 0) { solve(); } return 0; }