#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <utility>
#include <unordered_set>
#include <map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int n;
    ll cost;
    cin >> n >> cost;
    
    map<int, ll> delta;
    for (int i = 0; i < n; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        delta[a] += c;
        delta[b+1] -= c;
    }

    ll ret = 0;
    ll curr = 0;
    int prev = 0;
    for (auto [day, inc]: delta) {
        ll actual = min(curr, cost);
        ll val = actual * (day - prev);
        ret += val;

        prev = day;
        curr += inc;
    }
    cout << ret << endl;
}

#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>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
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, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
	int T;
	cin >> T;
	for (int i = 0; i < T; ++i) {
		int N, A, B;
		cin >> N >> A >> B;
		//よんせっと
		//まいなすよんせっと
		if ((A + B) > N) {
			cout << 0 << endl;
			continue;
		}
		mint ans = 1;
		ans *= (1 + N - B - A + 1);
		ans *= (N - B - A + 1);
		ans /= 2;
		ans *= (N - A + 1);
		ans *= (N - B + 1);
		ans *= 4;
		mint ans0 = 1;
		ans0 *= (N - B - A + 1);
		ans0 *= (N - B - A + 2);
		ans0 /= 2;
		ans0 *= ans0;
		ans0 *= 4;
		ans -= ans0;
		cout << ans << endl;
	}
	return 0;
}