#include <iostream>

#define MOD 1000000007

int main()
{
  int n = 0;
  long long t = 0, a = 0, b = 0;
  std::cin >> n;
  for(int i = 0; i < n; ++i)
  {
    long long result = 0, x1 = 0, x2 = 0, x3 = 0, x4 = 0;
    long long tmp1 = 0, tmp2 = 0;
    std::cin >> t >> a >> b;
    if((t - a - b) >= 0)
    {
      x4 = ((t - a - b) + 2)*((t - a - b) + 1) / 2;
    }
    else
    {
      x4 = 0;
    }
    x4 %= MOD;
    x3 = (2 * x4) % MOD;
    x2 = ((t - a + 1)) * ((t - b + 1)) % MOD - x3;
    x1 = (x2) * (x2) % MOD;
    tmp1 = ((t - a + 1)) * ((t - a + 1)) % MOD;
    tmp2 = ((t - b + 1)) * ((t - b + 1)) % MOD;
    result = (tmp1 * tmp2) - x1;
    result %= 1000000007;
    std::cout << result << std::endl;
  }
  return 0;
}
/*ॐ नमो भगवते वासुदेवाय नमः*/
#include<bits/stdc++.h>
using namespace std;

#define int long long
const int MOD = 1e9 + 7;
const double pi = 3.14159265359;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int binpow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int inverse(int x){
    return binpow(x, MOD - 2, MOD);
}

void solve()
{
    int n, ako = 0;
    cin >> n;
    vector<int> a(n), b(n), c;
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        c.push_back(2 * a[i] + b[i]);
        ako -= a[i];
    }
    sort(c.rbegin(), c.rend());
    int cnt = 0;
    for(int i = 0; i < n; i++){
        ako += c[i];
        cnt++;
        if(ako > 0) break;
    }
    cout << cnt << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n ";
}