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

#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
// #define _GLIBCXX_DEBUG
template <class T> using V = vector<T>;
#define ALL(v) (v).begin(),(v).end()
#define endl '\n'
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1000000007LL;
// const ll MOD = 998244353LL;
const ll INF = 1LL << 60;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const int dy2[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dx2[] = {1, 1, 0, -1, -1, -1, 0, 1};
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
 
/*--------------------------------------------------------------------------------
--------------------------------------------------------------------------------*/

int main() {
    ll n; cin >> n;
    V<ll> a(n), b(n);
    V<ll> c(n);
    ll ao = 0;
    rep(i, 0, n) cin >> a[i] >> b[i], ao += a[i];
    rep(i, 0, n){
        c[i]= b[i]+2*a[i];
    }
    sort(ALL(c));
    reverse(ALL(c));
    ll cnt = 0;
    rep(i, 0, n){
        ao -= c[i];
        cnt++;
        if(ao < 0){
            cout << cnt << endl;
            return 0;
        }
    }
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,n) for(ll i=0;i<n;i++)
#define loopn(i,j,n) for(ll i=j;i<n;i++)
#define m_arr(arr, n) vector<ll>arr(n)
#define m_arre(arr) vector<ll>arr
#define m_set(sat) set<ll>sat
#define ppn(name) pair<ll,ll>name
#define pp pair<ll,ll>
#define ff first
#define ss second
#define sort_all(arr) sort(arr.begin(), arr.end())
#define pi 3.141592653589793238
#define mod 998244353


ll gcd(ll a, ll b){if(a==0)return b;if(b==0)return a;return gcd(b%a, a);}
ll power(ll a, ll b){ll res=1;while(b>0){if(b%2!=0)res=res*1ll*a;b/=2;a=a*1ll*a;}return res;}

#define inf (power(2, 63)-1)
#define ninf (power(2, 63)+1)

void solve()
{
    ll l ,r ;
    cin>>l>>r;


    ll ans = (r-l);
    if(ans<l)
    {
        cout<<0<<endl;
        return;
    }
    ans=ans-l+1;
    ans = ans*1ll*(ans+1)/2;
    cout<<ans<<endl;
    return;

}

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