#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll mod = 1e9 + 7;

int main() {
	int t;
	cin >> t;
	rep(i, t) {
		ll n, a, b;
		cin >> n >> a >> b;
		ll c = (n - a + 1) * (n - b + 1) % mod;
		ll r = max(0LL, n - a - b + 1);
		ll t = (r * (r + 1) / 2) % mod;
		ll x = c * t % mod;
		ll y = t * t % mod;
		ll ans = 4 * (x - y) % mod;
		cout << (ans + mod) % mod  << endl;
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define Rep(i,j,n) for (ll i=(ll)(j);i<=(ll)(n);++i)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int mod = 998244353;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

/*
ll ti=clock();
cout<<("Execution Time: %.4lf sec", 1.0 * (clock() - ti) / CLOCKS_PER_SEC)<<endl;
*/

int main(){
  ll n;
  cin>>n;
  vl a(n),x(n);
  vector<Pll> p;
  rep(i,n){
    ll P;
    cin>>a[i]>>P>>x[i];
    p.pb(mp(P,i));
  }
  sort(all(p));
  rep(i,n){
    ll shop=p[i].S;
    if(x[shop]>a[shop]){
      print(p[i].F);
      return 0;
    }
  }
  print(-1);
}