//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <bitset>
#include <complex>
#include <limits>
#include <random>
#include<fstream>
#include<array>


using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int T;
	cin >> T;
	while (T--)
	{
		int N, A, B;
		cin >> N >> A >> B;

		int a = (N - A + 1)*(N - A + 1);
		int b = (N - B + 1)*(N - B + 1);
		a %= MOD;
		b %= MOD;

		int ans = a * b;
		ans %= MOD;

		int x = max(0LL, N - A - B + 1);
		x = x * (x + 1) / 2;
		x %= MOD;
		x *= 2;
		x %= MOD;

		int y = (N - A + 1)*(N - B + 1);
		y = (y - x + MOD) % MOD;
		y = y * y;
		y %= MOD;

		ans = (ans - y + MOD) % MOD;

		cout << ans << endl;
	}

	return 0;
}

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

int main(){
  int64_t a1,b1,c1,C,n,day;
  int64_t fee=0,feeall=0;
  vector<pair<int, int>> event;
  cin>>n>>C;
  for(int64_t i=0;i<2*n;i+=2){
    cin>>a1>>b1>>c1;
    event.push_back(make_pair(a1,c1));
    event.push_back(make_pair(b1+1,-1*c1));
  }
  sort(event.begin(),event.end());
  day=event[0].first;
  fee=event[0].second;
 // cout<<event[0].first<<"  "<<event[0].second<<endl;
  for(int i=1;i<2*n;i++){ 
    day=event[i].first-event[i-1].first;
    if(fee<C){
      feeall+=fee*day;
    }else{
      feeall+=C*day;
    }
    fee+=event[i].second;
   // cout<<event[i].first<<"  "<<event[i].second<<" "<<feeall<<endl;
  }
  cout<<feeall<<endl;
}
