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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
	int t;
	cin >> t;
	rep(i,t) {
		int n;
		int a,b;
		cin >> n >> a >> b;
		mint x1,x2,x3,x4;
		if (n-a-b >= 0) x4 = mint(n-a-b+2)*mint(n-a-b+1)/mint(2);
		else x4=0;
		x3 = mint(2)*x4;
		x2 = mint(n-a+1)*mint(n-b+1)-x3;
		x1 = x2*x2;
		mint ans;
		ans = mint(n-a+1)*mint(n-a+1)*mint(n-b+1)*mint(n-b+1)-x1;
		cout << ans << endl;
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define all(x) x.begin(), x.end()
#define printVec(vec) {for(auto &x : vec) cout << x <<" "; cout << endl; }
#define printMap(mp) {for(auto &p : mp) cout << p.first <<" " <<p.second <<endl;}
#define MOD 1000000007
#define hM 9999999900000001
#define inf 1e17
// const int maxN = 1;
// int BIT[maxN];
// void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
// int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}

void solve(int T) {
  int n;
  cin >> n;
  vector<vector<double>> arr(n);
  double corr =  0.01;
  for(int i = 0 ; i < n ; i++){
    double t, x, y;
    cin >> t >> x >> y;
    if(t == 2){
      y-=corr;
    }else if(t == 3){
      x+=corr;
    }else if(t == 4){
      x+=corr, y-=corr;
    }
    arr[i] = {x, y};
  }
  int cnt = 0;
  for(int i = 0 ; i < n ; i++){
    double myS = arr[i][0];
    double myE = arr[i][1];
    if(myE < myS)continue;
    for(int j = i+1; j < n ; j++){
      if(arr[j][0] > arr[j][1])continue;
      if(myS >= arr[j][0] && myS <= arr[j][1])
        cnt++;
      else if(myE >= arr[j][0] && myE <= arr[j][1])
        cnt++;
      else if(myS <= arr[j][0] && myE >= arr[j][1])
        cnt++;

    }
  }
  cout << cnt <<endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("inputf.txt", "r", stdin);
    freopen("outputf.txt", "w", stdout);
#endif

    int T = 1;
    //cin >> T;
    for (int t = 1; t <= T; t++) {
        solve(t);
    }

    cerr << "time taken : " << (float) clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}
