#include <bits/stdc++.h>
//#include "rubo.h"

#define pb push_back
#define SQ(x) (x)*(x)
#define ll long long
#define vc vector
#define F first
#define S second
#define in ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
using namespace std;

const int MAXN = 105;

int n;
ll k;
ll a[MAXN], b[MAXN];
ll MOD = 1000000007;
int c[MAXN];
const int MC = 20;

int add(int a, int b){
    return ((ll)a+(ll)b)%MOD;
}

struct matrix{
    int l;
    int e[MC][MC];

    void print(string s){
        printf("%s : \n",s.c_str());
        loop(i,l){
            loop(j,l){
                printf("%lld ",e[i][j]);
            }
            printf("\n");
        }
    }

    matrix operator * (const matrix &m) const{
        matrix res;
        res.l = l;
        loop(i,l){
            loop(j,l){
                res.e[i][j] = 0;
                loop(k,l){
                    res.e[i][j] += e[i][k]*m.e[k][j];
                }
            }
        }
        return res;
    }
};

matrix bin_pow(matrix &m, ll exp){
    if(exp == 1) return m;

    matrix h = bin_pow(m,exp/2);

    if(exp %2 == 0) return h*h;

    return h*h*m;
}

matrix vat_pow(matrix &m, ll exp){
    if(exp == 1) return m;

    matrix res = m*m;

    for(ll i = 3; i <= exp; i++){
        res = res*m;
    }
    return res;
}

int main() {
    scanf("%d%lld",&n,&k);
    loop(i,n){
        scanf("%lld%lld%d",a+i,b+i,c+i);
    }

    b[n-1] = min(b[n-1],k);

    ll x[MC];
    x[0] = 1;
    for(int j = 1; j < MC; j++)
        x[j] = 0;

    ll y[MC];
    for(int I = 0; I < n; I++){
        matrix m;
        m.l = c[I]+1;
        ll L = b[I] - a[I];
        loop(i,m.l)
            loop(j,m.l)
                 if(abs(i-j ) <= 1)
                     m.e[i][j] = 1;
                 else
                     m.e[i][j] = 0;

        m = vat_pow(m,L);
        loop(i,MC) y[i] = 0;

        loop(i,m.l){
            y[i] = 0;
            loop(j,m.l){
                y[i] += m.e[i][j]*x[j];
                y[i] %= MOD;
            }
        }

        loop(i,MC) x[i] = y[i];
    }

    ll res = x[0];

    printf("%lld\n",res);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long MOD = 1e9 + 7;
long **workspace;

void multiply(long **a, long**b, short rows, short same, short cols, long **res) {
  for (long i = 0; i < rows; ++i)
	for (long j = 0; j < cols; ++j) {
	  unsigned long long temp = 0; // > 15 * 10^18
	  for (long k = 0; k < same; ++k)
		temp += a[i][k] * b[k][j] % MOD;
	  workspace[i][j] = temp % MOD;
	}
  for (short i = 0; i < rows; ++i)
	for (short j = 0; j < cols; ++j)
	  res[i][j] = workspace[i][j];
}

int main() {
  short n;
  long long k;
  cin >> n >> k;

  // setup matrices
  long **res = new long*[15];
  long **multiplier = new long*[15];
  long **acc = new long*[15];
  workspace = new long*[15];
  for (short i = 0; i < 15; ++i) {
	res[i] = new long[0];
	res[i][0] = (i == 0);
	multiplier[i] = new long[15];
	acc[i] = new long[15];
	workspace[i] = new long[15];
  }

  // algorithm
  while (n--) {
	long long a, b;
	short c;
	cin >> a >> b >> c;

	// setup matrices
	for (short i = 0; i < 15; ++i)
	  for (short j = 0; j < 15; ++j)
		if (j <= c and i <= c)
		  multiplier[i][j] = (abs(i - j) <= 1);
		else
		  multiplier[i][j] = 0;

	for (short i = 0; i < 15; ++i)
	  for (short j = 0; j < 15; ++j)
		acc[i][j] = (i == j);

	// multiplication
	long long delta = min(k, b) - a;
	while (delta > 0) {
	  if (delta % 2)
		multiply(multiplier, acc, 15, 15, 15, acc);
	  delta /= 2;
	  if (delta == 0) continue;
	  multiply(multiplier, multiplier, 15, 15, 15, multiplier);
	}
	multiply(acc, res, 15, 15, 1, res);
  }

  cout << res[0][0] << endl;
}


#include <bits/stdc++.h>

using namespace std;

const long MOD = 1e9 + 7;
long **workspace;

void multiply(long **a, long**b, short rows, short same, short cols, long **res) {
  for (long i = 0; i < rows; ++i)
	for (long j = 0; j < cols; ++j) {
	  unsigned long long temp = 0; // > 15 * 10^18
	  for (long k = 0; k < same; ++k)
		temp += a[i][k] * b[k][j];
	  workspace[i][j] = temp % MOD;
	}
  for (short i = 0; i < rows; ++i)
	for (short j = 0; j < cols; ++j)
	  res[i][j] = workspace[i][j];
}

int main() {
  short n;
  long long k;
  cin >> n >> k;

  // setup matrices
  long **res = new long*[15];
  long **multiplier = new long*[15];
  long **acc = new long*[15];
  workspace = new long*[15];
  for (short i = 0; i < 15; ++i) {
	res[i] = new long[0];
	res[i][0] = (i == 0);
	multiplier[i] = new long[15];
	acc[i] = new long[15];
	workspace[i] = new long[15];
  }

  // algorithm
  while (n--) {
	long long a, b;
	short c;
	cin >> a >> b >> c;

	// setup matrices
	for (short i = 0; i < 15; ++i)
	  for (short j = 0; j < 15; ++j)
		if (j <= c and i <= c)
		  multiplier[i][j] = (abs(i - j) <= 1);
		else
		  multiplier[i][j] = 0;

	for (short i = 0; i < 15; ++i)
	  for (short j = 0; j < 15; ++j)
		acc[i][j] = (i == j);

	// multiplication
	long long delta = min(k, b) - a;
	while (delta > 0) {
	  if (delta % 2)
		multiply(multiplier, acc, 15, 15, 15, acc);
	  delta /= 2;
	  if (delta == 0) continue;
	  multiply(multiplier, multiplier, 15, 15, 15, multiplier);
	}
	multiply(acc, res, 15, 15, 1, res);
  }

  cout << res[0][0] << endl;
}


#include <bits/stdc++.h>

using namespace std;

const long MOD = 1e9 + 7;
long **workspace;

void multiply(long **a, long**b, short rows, short same, short cols, long **res) {
  for (long i = 0; i < rows; ++i)
	for (long j = 0; j < cols; ++j) {
	  unsigned long long temp = 0; // > 16 * 10^18
	  for (long k = 0; k < same; ++k)
		temp += a[i][k] * b[k][j];
	  workspace[i][j] = temp % MOD;
	}
  for (short i = 0; i < rows; ++i)
	for (short j = 0; j < cols; ++j)
	  res[i][j] = workspace[i][j];
}

int main() {
  short n;
  long long k;
  cin >> n >> k;

  // setup matrices
  long **res = new long*[16];
  long **multiplier = new long*[16];
  long **acc = new long*[16];
  workspace = new long*[16];
  for (short i = 0; i < 16; ++i) {
	res[i] = new long[0];
	res[i][0] = (i == 0);
	multiplier[i] = new long[16];
	acc[i] = new long[16];
	workspace[i] = new long[16];
  }

  // algorithm
  while (n--) {
	long long a, b;
	short c;
	cin >> a >> b >> c;

	// setup matrices
	for (short i = 0; i < 16; ++i)
	  for (short j = 0; j < 16; ++j)
		if (j <= c and i <= c)
		  multiplier[i][j] = (abs(i - j) <= 1);
		else
		  multiplier[i][j] = 0;

	for (short i = 0; i < 16; ++i)
	  for (short j = 0; j < 16; ++j)
		acc[i][j] = (i == j);

	// multiplication
	long long delta = min(k, b) - a;
	while (delta > 0) {
	  if (delta % 2)
		multiply(multiplier, acc, 16, 16, 16, acc);
	  delta /= 2;
	  if (delta == 0) continue;
	  multiply(multiplier, multiplier, 16, 16, 16, multiplier);
	}
	multiply(acc, res, 16, 16, 1, res);
  }

  cout << res[0][0] << endl;
}


#include <bits/stdc++.h>

using namespace std;

const long MOD = 1e9 + 7;
long **workspace;

void multiply(long **a, long**b, short rows, short same, short cols, long **res) {
  for (long i = 0; i < rows; ++i)
	for (long j = 0; j < cols; ++j) {
	  unsigned long long temp = 0; // > 16 * 10^18
	  for (long k = 0; k < same; ++k)
		temp += (long long)a[i][k] * b[k][j];
	  workspace[i][j] = temp % MOD;
	}
  for (short i = 0; i < rows; ++i)
	for (short j = 0; j < cols; ++j)
	  res[i][j] = workspace[i][j];
}

int main() {
  short n;
  long long k;
  cin >> n >> k;

  // setup matrices
  long **res = new long*[16];
  long **multiplier = new long*[16];
  long **acc = new long*[16];
  workspace = new long*[16];
  for (short i = 0; i < 16; ++i) {
	res[i] = new long[0];
	res[i][0] = (i == 0);
	multiplier[i] = new long[16];
	acc[i] = new long[16];
	workspace[i] = new long[16];
  }

  // algorithm
  while (n--) {
	long long a, b;
	short c;
	cin >> a >> b >> c;

	// setup matrices
	for (short i = 0; i < 16; ++i)
	  for (short j = 0; j < 16; ++j)
		if (j <= c and i <= c)
		  multiplier[i][j] = (abs(i - j) <= 1);
		else
		  multiplier[i][j] = 0;

	for (short i = 0; i < 16; ++i)
	  for (short j = 0; j < 16; ++j)
		acc[i][j] = (i == j);

	// multiplication
	long long delta = min(k, b) - a;
	while (delta > 0) {
	  if (delta % 2)
		multiply(multiplier, acc, 16, 16, 16, acc);
	  delta /= 2;
	  if (delta == 0) continue;
	  multiply(multiplier, multiplier, 16, 16, 16, multiplier);
	}
	multiply(acc, res, 16, 16, 1, res);
  }

  cout << res[0][0] << endl;
}


#include <bits/stdc++.h>

using namespace std;

const long MOD = 1e9 + 7;
long **workspace;

void multiply(long **a, long**b, short rows, short same, short cols) {
  for (long i = 0; i < rows; ++i)
	for (long j = 0; j < cols; ++j) {
	  unsigned long long temp = 0; // > 15 * 10^18
	  for (long k = 0; k < same; ++k)
		temp += a[i][k] * b[k][j];
	  workspace[i][j] = temp % MOD;
	}
}

void copy(long **source, long **dest, short rows, short cols) {
  for (short i = 0; i < rows; ++i)
	for (short j = 0; j < cols; ++j)
	  dest[i][j] = source[i][j];
}

int main() {
  short n;
  long long k;
  cin >> n >> k;

  // setup matrices
  long **res = new long*[15];
  long **multiplier = new long*[15];
  long **acc = new long*[15];
  workspace = new long*[15];
  for (short i = 0; i < 15; ++i) {
	res[i] = new long[0];
	res[i][0] = (i == 0);
	multiplier[i] = new long[15];
	acc[i] = new long[15];
	workspace[i] = new long[15];
  }

  // algorithm
  while (n--) {
	long long a, b;
	short c;
	cin >> a >> b >> c;

	// setup matrices
	for (short i = 0; i < 15; ++i)
	  for (short j = 0; j < 15; ++j) {
		if (j <= c)
		  multiplier[i][j] = (abs(i - j) <= 1);
		else
		  multiplier[i][j] = 0;
	  }
	for (short i = 0; i < 15; ++i)
	  for (short j = 0; j < 15; ++j)
		acc[i][j] = (i == j);

	// multiplication
	long long delta = min(k, b) - a;
	while (delta > 0) {
	  if (delta % 2) {
		multiply(multiplier, acc, 15, 15, 15);
		copy(workspace, acc, 15, 15);
	  }
	  delta /= 2;
	  if (delta == 0) continue;
	  multiply(multiplier, multiplier, 15, 15, 15);
	  copy(workspace, multiplier, 15, 15);
	}
	multiply(acc, res, 15, 15, 1);
  }

  cout << workspace[0][0] << endl;
}


#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define PB push_back
#define N 105
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int n, k, l[N], r[N], c[N], xx;

struct matrix
{
    int a[16][16];
    matrix()
    {
        memset(a, 0, sizeof a);
    }
};

matrix nhan(matrix p, matrix q)
{
    matrix kk = matrix();
    for (int i = 0; i <= xx; i++)
        for (int j = 0; j <= xx; j++)
            for (int k = 0; k <= xx; k++)
                kk.a[i][j] = (kk.a[i][j] + p.a[i][k]*q.a[k][j] % mod) % mod;
    return kk;
}
matrix power(matrix a, int b)
{
    if (b == 1) return a;
    matrix x = power(a, b/2);
    x = nhan(x, x);
    if (b % 2) return nhan(x, a);
    return x;
}
void nhap()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> l[i] >> r[i] >> c[i];
    r[n] = k;
}
void solve()
{
    matrix res = matrix();
    res.a[0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        matrix zz = matrix();

        for (int j = 0; j <= c[i]; j++)
            for (int z = max(0, j-1); z <= min(c[i], j+1); z++) zz.a[j][z] = 1;
        xx = c[i];
        zz = power(zz, r[i] - l[i]);
        res = nhan(res, zz);
    }
    cout <<res.a[0][0];
}

int main()
{
   // freopen("INP.TXT", "r", stdin);
    nhap();
    solve();
}


#include <bits/stdc++.h>
#define pii pair<ll, ll>
#define mp make_pair
#define F first
#define S second
#define PB push_back
#define N 105
#define ll long long
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

ll n, k, l[N], r[N], c[N], xx;

struct matrix
{
    ll a[16][16];
    matrix()
    {
        memset(a, 0, sizeof a);
    }
};

matrix nhan(matrix p, matrix q)
{
    matrix kk = matrix();
    for (ll i = 0; i <= xx; i++)
        for (ll j = 0; j <= xx; j++)
            for (ll k = 0; k <= xx; k++)
                kk.a[i][j] = (kk.a[i][j] + p.a[i][k]*q.a[k][j] % mod) % mod;
    return kk;
}
matrix power(matrix a, ll b)
{
    if (b == 1) return a;
    matrix x = power(a, b/2);
    x = nhan(x, x);
    if (b % 2) return nhan(x, a);
    return x;
}
void nhap()
{
    cin >> n >> k;
    for (ll i = 1; i <= n; i++)
        cin >> l[i] >> r[i] >> c[i];
    r[n] = k;
}
void solve()
{
    matrix res = matrix();
    res.a[0][0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        matrix zz = matrix();

        for (ll j = 0; j <= c[i]; j++)
            for (ll z = max(0ll, j-1); z <= min(c[i], j+1); z++) zz.a[j][z] = 1;
        xx = c[i];
        if (r[i] - l[i] > 0)
        {
            zz = power(zz, r[i] - l[i]);
            res = nhan(res, zz);
        }
    }
    cout <<res.a[0][0];
}

int main()
{
    //freopen("INP.TXT", "r", stdin);
    nhap();
    solve();
    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define PB push_back
#define N 105
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int n, k, l[N], r[N], c[N], xx;

struct matrix
{
    int a[16][16];
    matrix()
    {
        memset(a, 0, sizeof a);
    }
};

matrix nhan(matrix p, matrix q)
{
    matrix kk = matrix();
    for (int i = 0; i <= xx; i++)
        for (int j = 0; j <= xx; j++)
            for (int k = 0; k <= xx; k++)
                kk.a[i][j] = (kk.a[i][j] + p.a[i][k]*q.a[k][j] % mod) % mod;
    return kk;
}
matrix power(matrix a, int b)
{
    if (b == 1) return a;
    matrix x = power(a, b/2);
    x = nhan(x, x);
    if (b % 2) return nhan(x, a);
    return x;
}
void nhap()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> l[i] >> r[i] >> c[i];
    r[n] = k;
}
void solve()
{
    matrix res = matrix();
    res.a[0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        matrix zz = matrix();

        for (int j = 0; j <= c[i]; j++)
            for (int z = max(0, j-1); z <= min(c[i], j+1); z++) zz.a[j][z] = 1;
        xx = c[i];
        zz = power(zz, r[i] - l[i]);
        res = nhan(res, zz);
    }
    cout <<res.a[0][0];
}

int main()
{
    freopen("INP.TXT", "r", stdin);
    nhap();
    solve();
}


#include <bits/stdc++.h>
#define pii pair<ll, ll>
#define mp make_pair
#define F first
#define S second
#define PB push_back
#define N 105
#define ll long long
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

ll n, k, l[N], r[N], c[N], xx;

struct matrix
{
    ll a[16][16];
    matrix()
    {
        memset(a, 0, sizeof a);
    }
};

matrix nhan(matrix p, matrix q)
{
    matrix kk = matrix();
    for (ll i = 0; i <= xx; i++)
        for (ll j = 0; j <= xx; j++)
            for (ll k = 0; k <= xx; k++)
                kk.a[i][j] = (kk.a[i][j] + p.a[i][k]*q.a[k][j] % mod) % mod;
    return kk;
}
matrix power(matrix a, ll b)
{
    if (b == 1) return a;
    matrix x = power(a, b/2);
    x = nhan(x, x);
    if (b % 2) return nhan(x, a);
    return x;
}
void nhap()
{
    cin >> n >> k;
    for (ll i = 1; i <= n; i++)
        cin >> l[i] >> r[i] >> c[i];
    r[n] = k;
}
void solve()
{
    matrix res = matrix();
    res.a[0][0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        matrix zz = matrix();

        for (ll j = 0; j <= c[i]; j++)
            for (ll z = max(0ll, j-1); z <= min(c[i], j+1); z++) zz.a[j][z] = 1;
        xx = c[i];
        zz = power(zz, r[i] - l[i]);
        res = nhan(res, zz);
    }
    cout <<res.a[0][0];
}

int main()
{
    //freopen("INP.TXT", "r", stdin);
    nhap();
    solve();
}


#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define PB push_back
#define N 105
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int n, k, l[N], r[N], c[N], xx;

struct matrix
{
    int a[16][16];
    matrix()
    {
        memset(a, 0, sizeof a);
    }
};

matrix nhan(matrix p, matrix q)
{
    matrix kk = matrix();
    for (int i = 0; i <= xx; i++)
        for (int j = 0; j <= xx; j++)
            for (int k = 0; k <= xx; k++)
                kk.a[i][j] = (kk.a[i][j] + p.a[i][k]*q.a[k][j] % mod) % mod;
    return kk;
}
matrix power(matrix a, int b)
{
    if (b == 1) return a;
    matrix x = power(a, b/2);
    x = nhan(x, x);
    if (b % 2) return nhan(x, a);
    return x;
}
void nhap()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> l[i] >> r[i] >> c[i];
    r[n] = k;
}
void solve()
{
    matrix res = matrix();
    res.a[0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        matrix zz = matrix();

        for (int j = 0; j <= c[i]; j++)
            for (int z = max(0, j-1); z <= min(c[i], j+1); z++) zz.a[j][z] = 1;
        xx = c[i];
        zz = power(zz, r[i] - l[i]);
        res = nhan(res, zz);
    }
    cout <<res.a[0][0];
}

int main()
{
    //freopen("INP.TXT", "r", stdin);
    nhap();
    solve();
}


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

const long long mod = 1000000007;

struct Matrix {
	long long a[16][16];

	Matrix operator * (const Matrix& rhs) const {
		Matrix ans;
		memset(&ans, 0, sizeof(ans));
		for(int k = 0; k < 16; k++) {
			for(int i = 0; i < 16; i++) {
				for(int j = 0; j < 16; j++) {
					ans.a[i][k] += (a[i][j] * rhs.a[j][k]) % mod;
					ans.a[i][j] %= mod;
				}
			}
		}
		return ans;
	}

	Matrix my_pow(int k) {
		Matrix ans, ret = *this;
		memset(&ans, 0, sizeof(ans));
		for(int i = 0; i < 16; i++) {
			ans.a[i][i] = 1;
		}

		while(k) {
			if(k & 1)
				ans = ans * ret;
			ret = ret * ret;
			k /= 2;
		}

		return ans;
	}
};

int main() {
	int n;
	long long k;
	scanf("%d%lld", &n, &k);

	Matrix ans;
	memset(&ans, 0, sizeof(ans));
	for(int i = 0; i < 16; i++)
		ans.a[i][i] = 1;

	for(int i = 0; i < n; i++) {
		long long a, b, c;
		scanf("%lld%lld%lld", &a, &b, &c);
		if(b > k) b = k;
		Matrix t;
		memset(&t, 0, sizeof(t));
		for(int i = 0; i <= c; i++) {
			if(i != 0) t.a[i][i - 1] = 1;
			t.a[i][i] = 1;
			if(i != c) t.a[i][i + 1] = 1;
		}

		t = t.my_pow(b - a);
		ans = ans * t;
	}

	printf("%lld\n", ans.a[0][0]);
	return 0;
}


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

const long long mod = 1000000007;

struct Matrix {
	int a[16][16];

	Matrix operator * (const Matrix& rhs) const {
		Matrix ans;
		memset(&ans, 0, sizeof(ans));
		for(int k = 0; k < 16; k++) {
			for(int i = 0; i < 16; i++) {
				for(int j = 0; j < 16; j++) {
					ans.a[i][k] += (a[i][j] * rhs.a[j][k]) % mod;
					ans.a[i][j] %= mod;
				}
			}
		}
		return ans;
	}

	Matrix my_pow(int k) {
		Matrix ans, ret = *this;
		memset(&ans, 0, sizeof(ans));
		for(int i = 0; i < 16; i++) {
			ans.a[i][i] = 1;
		}

		while(k) {
			if(k & 1)
				ans = ans * ret;
			ret = ret * ret;
			k /= 2;
		}

		return ans;
	}
};

int main() {
	int n;
	long long k;
	scanf("%d%lld", &n, &k);

	Matrix ans;
	memset(&ans, 0, sizeof(ans));
	for(int i = 0; i < 16; i++)
		ans.a[i][i] = 1;

	for(int i = 0; i < n; i++) {
		long long a, b, c;
		scanf("%lld%lld%lld", &a, &b, &c);
		if(b > k) b = k;
		Matrix t;
		memset(&t, 0, sizeof(t));
		for(int i = 0; i <= c; i++) {
			if(i != 0) t.a[i][i - 1] = 1;
			t.a[i][i] = 1;
			if(i != c) t.a[i][i + 1] = 1;
		}

		t = t.my_pow(b - a);
		ans = ans * t;
	}

	printf("%lld\n", ans.a[0][0]);
	return 0;
}


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

const long long mod = 1000000007;

struct Matrix {
	long long a[16][16];

	Matrix operator * (const Matrix& rhs) const {
		Matrix ans;
		memset(&ans, 0, sizeof(ans));
		for(int k = 0; k < 16; k++) {
			for(int i = 0; i < 16; i++) {
				for(int j = 0; j < 16; j++) {
					ans.a[i][k] += (a[i][j] * rhs.a[j][k]) % mod;
					ans.a[i][j] %= mod;
				}
			}
		}
		return ans;
	}

	Matrix my_pow(long long k) {
		Matrix ans, ret = *this;
		memset(&ans, 0, sizeof(ans));
		for(int i = 0; i < 16; i++) {
			ans.a[i][i] = 1;
		}

		while(k) {
			if(k & 1)
				ans = ans * ret;
			ret = ret * ret;
			k /= 2;
		}

		return ans;
	}
};

int main() {
	int n;
	long long k;
	scanf("%d%lld", &n, &k);

	Matrix ans;
	memset(&ans, 0, sizeof(ans));
	for(int i = 0; i < 16; i++)
		ans.a[i][i] = 1;

	for(int i = 0; i < n; i++) {
		long long a, b, c;
		scanf("%lld%lld%lld", &a, &b, &c);
		if(b > k) b = k;
		Matrix t;
		memset(&t, 0, sizeof(t));
		for(int j = 0; j <= c; j++) {
			if(j != 0) t.a[j][j - 1] = 1;
			t.a[j][j] = 1;
			if(j != c) t.a[j][j + 1] = 1;
		}

		t = t.my_pow(b - a);
		ans = ans * t;
	}

	printf("%lld\n", ans.a[0][0]);
	return 0;
}


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

const long long mod = 1000000007;

struct Matrix {
	long long a[16][16];

	Matrix operator * (const Matrix& rhs) const {
		Matrix ans;
		memset(&ans, 0, sizeof(ans));
		for(int k = 0; k < 16; k++) {
			for(int i = 0; i < 16; i++) {
				for(int j = 0; j < 16; j++) {
					ans.a[i][k] += (a[i][j] * rhs.a[j][k]) % mod;
					ans.a[i][j] %= mod;
				}
			}
		}
		return ans;
	}

	Matrix my_pow(int k) {
		Matrix ans, ret = *this;
		memset(&ans, 0, sizeof(ans));
		for(int i = 0; i < 16; i++) {
			ans.a[i][i] = 1;
		}

		while(k) {
			if(k & 1)
				ans = ans * ret;
			ret = ret * ret;
			k /= 2;
		}

		return ans;
	}
};

int main() {
	int n;
	long long k;
	scanf("%d%lld", &n, &k);

	Matrix ans;
	memset(&ans, 0, sizeof(ans));
	for(int i = 0; i < 16; i++)
		ans.a[i][i] = 1;

	for(int i = 0; i < n; i++) {
		long long a, b, c;
		scanf("%lld%lld%lld", &a, &b, &c);
		if(b > k) b = k;
		Matrix t;
		memset(&t, 0, sizeof(t));
		for(int j = 0; j <= c; j++) {
			if(j != 0) t.a[j][j - 1] = 1;
			t.a[j][j] = 1;
			if(j != c) t.a[j][j + 1] = 1;
		}

		t = t.my_pow(b - a);
		ans = ans * t;
	}

	printf("%lld\n", ans.a[0][0]);
	return 0;
}


/********************************************
*                                           *
*    Solved By : Bir Bahadur Khatri(B'ru)   *
*      Be Positive,be Happy.                *
*                                           *
*********************************************/
#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define MP make_pair
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#include<bits/stdc++.h>
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define LL long long int
#define S1(a) a=in<int>()
#define SL1(a) a=in<LL>()
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define S2(a,b) a=in<int>(),b=in<int>()
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define _cin ios_base::sync_with_stdio(0); cin.tie(0)
#define cp printf("***** here here here here *****\n");
#define trace1(x)                cerr << #x << ": " << x << endl;
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
template <typename T> LL isLeft(T a,T b,T c) {return(a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y);}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
///**********************************************************//

#define MD1 1000000007ULL
#define MD2 1000000009ULL
#define MD3 1000000021ULL
#define BS1 10000019ULL
#define BS2 10000079ULL
#define BS3 10000103ULL
#define PUL pair<ULL,ULL>
#define PLL pair<LL,LL>
#define PII pair<int,int>

#define lchild lft,l,mid
#define rchild rgt,mid+1,r
#define ngood  r<st||l>ed
#define good   st<=l&&ed>=r
#define seg    int mid=(l+r)/2,lft=2*id,rgt=lft+1

///         0123456789
#define MX  500007
#define MOD 1000000007
#define INF 2000000000000000LL
#define EPS 1e-9

/// ==========================================////

struct Matrix {
    LL ar[16][16];
};

const int N=16;

Matrix MUL(Matrix a,Matrix b) {
    Matrix ans;
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            ans.ar[i][j]=0;
            for(int k=0;k<N;k++) {
                ans.ar[i][j]=(ans.ar[i][j]+a.ar[i][k]*b.ar[k][j])%MOD;
            }
        }
    }
    return ans;
}

Matrix Big_Mod(Matrix a,LL n) {
    Matrix ans=a;
    n--;
    while(n) {
        if(n&1) {
            ans=MUL(ans,a);
        }
        a=MUL(a,a);
        n/=2;
    }
    return ans;
}

LL a[MX];
LL b[MX];
LL c[MX];
Matrix Ans;

void how() {
    F(i,0,N) F(j,0,N) Ans.ar[i][j]=0;
    F(i,0,N) Ans.ar[0][0]=1;
}
Matrix Makebase(int p,LL n) {
    Matrix base;
    F(i,0,N) F(j,0,N) base.ar[i][j]=0;
    for(int i=0;i<=c[p];i++) {
        for(int j=-1;j<=1;j++) {
            int ps=i+j;
            if(ps>=0&&ps<=(c[p])) {
                base.ar[i][ps]=1;
            }
        }
    }
    return Big_Mod(base,n);
}

void lol(int p) {
    LL l=a[p],r=b[p];
    LL gap=r-l;
    Matrix nw=Makebase(p,gap);
    Ans=MUL(Ans,nw);
}

int main(){

    how();
    LL n,k;
    cin>>n>>k;

    F(i,1,n+1) {
        cin>>a[i]>>b[i]>>c[i];
    }

    if(a[n]>=k) {
        n--;
    }

    b[n]=k;
    F(i,1,n+1) {
        lol(i);
    }
    cout<<Ans.ar[0][0]<<endl;

    return 0;
}
///============= Thank You ===================///


/********************************************
*                                           *
*    Solved By : Bir Bahadur Khatri(B'ru)   *
*      Be Positive,be Happy.                *
*                                           *
*********************************************/
#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define MP make_pair
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#include<bits/stdc++.h>
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define LL long long int
#define S1(a) a=in<int>()
#define SL1(a) a=in<LL>()
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define S2(a,b) a=in<int>(),b=in<int>()
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define _cin ios_base::sync_with_stdio(0); cin.tie(0)
#define cp printf("***** here here here here *****\n");
#define trace1(x)                cerr << #x << ": " << x << endl;
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
template <typename T> LL isLeft(T a,T b,T c) {return(a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y);}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
///**********************************************************//

#define MD1 1000000007ULL
#define MD2 1000000009ULL
#define MD3 1000000021ULL
#define BS1 10000019ULL
#define BS2 10000079ULL
#define BS3 10000103ULL
#define PUL pair<ULL,ULL>
#define PLL pair<LL,LL>
#define PII pair<int,int>

#define lchild lft,l,mid
#define rchild rgt,mid+1,r
#define ngood  r<st||l>ed
#define good   st<=l&&ed>=r
#define seg    int mid=(l+r)/2,lft=2*id,rgt=lft+1

///         0123456789
#define MX  500007
#define MOD 1000000007
#define INF 2000000000000000LL
#define EPS 1e-9

/// ==========================================////

struct Matrix {
    LL ar[16][16];
};

const int N=16;

Matrix MUL(Matrix a,Matrix b) {
    Matrix ans;
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            ans.ar[i][j]=0;
            for(int k=0;k<N;k++) {
                ans.ar[i][j]=(ans.ar[i][j]+a.ar[i][k]*b.ar[k][j])%MOD;
            }
        }
    }
    return ans;
}

Matrix Big_Mod(Matrix a,LL n) {
    Matrix ans=a;
    n--;
    while(n) {
        if(n&1) {
            ans=MUL(ans,a);
        }
        a=MUL(a,a);
        n/=2;
    }
    return ans;
}

LL a[MX];
LL b[MX];
LL c[MX];
Matrix Makebase(int p,LL n) {
    Matrix base;
    F(i,0,N) F(j,0,N) base.ar[i][j]=0;
    for(int i=0;i<=c[p];i++) {
        for(int j=-1;j<=1;j++) {
            int ps=i+j;
            if(ps>=0) {
                base.ar[i][ps]=1;
            }
        }
    }
    return Big_Mod(base,n);
}

vector<LL> lol(vector<LL> v,int p) {
    LL l=a[p],r=b[p],ps=c[p];
    LL gap=r-l;
    Matrix nw=Makebase(p,gap);
    vector<LL> ans;
    for(int i=0;i<N;i++) {
        LL an=0;
        F(j,0,N) {
            an=(an+v[j]*nw.ar[i][j])%MOD;
        }
        ans.PB(an);
    }
    return ans;
}

int main(){

    LL n,k;
    cin>>n>>k;

    F(i,1,n+1) {
        cin>>a[i]>>b[i]>>c[i];
    }
    b[n]=k;
    vector<LL> v;
    v.PB(1);
    F(i,1,16) {
        v.PB(0);
    }

    F(i,1,n+1) {
        v=lol(v,i);
    }
    cout<<v[0]<<endl;

    return 0;
}
///============= Thank You ===================///


/********************************************
*                                           *
*    Solved By : Bir Bahadur Khatri(B'ru)   *
*      Be Positive,be Happy.                *
*                                           *
*********************************************/
#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define MP make_pair
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#include<bits/stdc++.h>
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define LL long long int
#define S1(a) a=in<int>()
#define SL1(a) a=in<LL>()
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define S2(a,b) a=in<int>(),b=in<int>()
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define _cin ios_base::sync_with_stdio(0); cin.tie(0)
#define cp printf("***** here here here here *****\n");
#define trace1(x)                cerr << #x << ": " << x << endl;
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
template <typename T> LL isLeft(T a,T b,T c) {return(a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y);}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
///**********************************************************//

#define MD1 1000000007ULL
#define MD2 1000000009ULL
#define MD3 1000000021ULL
#define BS1 10000019ULL
#define BS2 10000079ULL
#define BS3 10000103ULL
#define PUL pair<ULL,ULL>
#define PLL pair<LL,LL>
#define PII pair<int,int>

#define lchild lft,l,mid
#define rchild rgt,mid+1,r
#define ngood  r<st||l>ed
#define good   st<=l&&ed>=r
#define seg    int mid=(l+r)/2,lft=2*id,rgt=lft+1

///         0123456789
#define MX  500007
#define MOD 1000000007
#define INF 2000000000000000LL
#define EPS 1e-9

/// ==========================================////

struct Matrix {
    LL ar[16][16];
};

const int N=16;

Matrix MUL(Matrix a,Matrix b) {
    Matrix ans;
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            ans.ar[i][j]=0;
            for(int k=0;k<N;k++) {
                ans.ar[i][j]=(ans.ar[i][j]+a.ar[i][k]*b.ar[k][j])%MOD;
            }
        }
    }
    return ans;
}

Matrix Big_Mod(Matrix a,LL n) {
    Matrix ans=a;
    n--;
    while(n) {
        if(n&1) {
            ans=MUL(ans,a);
        }
        a=MUL(a,a);
        n/=2;
    }
    return ans;
}

LL a[MX];
LL b[MX];
LL c[MX];
Matrix Makebase(int p,LL n) {
    Matrix base;
    F(i,0,N) F(j,0,N) base.ar[i][j]=0;
    for(int i=0;i<=c[p];i++) {
        for(int j=-1;j<=1;j++) {
            int ps=i+j;
            if(ps>=0&&ps<=c[p]) {
                base.ar[i][ps]=1;
            }
        }
    }
    return Big_Mod(base,n);
}

vector<LL> lol(vector<LL> v,int p) {

    vector<LL> vv;
    F(i,0,N) {
        if(i<=c[p]) vv.PB(v[i]);
        else vv.PB(0);
    }
    v=vv;
    LL l=a[p],r=b[p],ps=c[p];
    LL gap=r-l;
    Matrix nw=Makebase(p,gap);
    vector<LL> ans;
    for(int i=0;i<N;i++) {
        LL an=0;
        F(j,0,N) {
            an=(an+v[j]*nw.ar[i][j])%MOD;
        }
        ans.PB(an);
    }
    return ans;
}

int main(){

    LL n,k;
    cin>>n>>k;

    F(i,1,n+1) {
        cin>>a[i]>>b[i]>>c[i];
    }
    b[n]=k;
    vector<LL> v;
    v.PB(1);
    F(i,1,16) {
        v.PB(0);
    }

    F(i,1,n+1) {
        v=lol(v,i);
    }
    cout<<v[0]<<endl;

    return 0;
}
///============= Thank You ===================///


/********************************************
*                                           *
*    Solved By : Bir Bahadur Khatri(B'ru)   *
*      Be Positive,be Happy.                *
*                                           *
*********************************************/
#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define MP make_pair
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#include<bits/stdc++.h>
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define LL long long int
#define S1(a) a=in<int>()
#define SL1(a) a=in<LL>()
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define S2(a,b) a=in<int>(),b=in<int>()
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define _cin ios_base::sync_with_stdio(0); cin.tie(0)
#define cp printf("***** here here here here *****\n");
#define trace1(x)                cerr << #x << ": " << x << endl;
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
template <typename T> LL isLeft(T a,T b,T c) {return(a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y);}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
///**********************************************************//

#define MD1 1000000007ULL
#define MD2 1000000009ULL
#define MD3 1000000021ULL
#define BS1 10000019ULL
#define BS2 10000079ULL
#define BS3 10000103ULL
#define PUL pair<ULL,ULL>
#define PLL pair<LL,LL>
#define PII pair<int,int>

#define lchild lft,l,mid
#define rchild rgt,mid+1,r
#define ngood  r<st||l>ed
#define good   st<=l&&ed>=r
#define seg    int mid=(l+r)/2,lft=2*id,rgt=lft+1

///         0123456789
#define MX  500007
#define MOD 1000000007
#define INF 2000000000000000LL
#define EPS 1e-9

/// ==========================================////

struct Matrix {
    LL ar[16][16];
};

const int N=16;

Matrix MUL(Matrix a,Matrix b) {
    Matrix ans;
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            ans.ar[i][j]=0;
            for(int k=0;k<N;k++) {
                ans.ar[i][j]=(ans.ar[i][j]+a.ar[i][k]*b.ar[k][j])%MOD;
            }
        }
    }
    return ans;
}

Matrix Big_Mod(Matrix a,LL n) {
    Matrix ans=a;
    n--;
    while(n) {
        if(n&1) {
            ans=MUL(ans,a);
        }
        a=MUL(a,a);
        n/=2;
    }
    return ans;
}

LL a[MX];
LL b[MX];
LL c[MX];
Matrix Ans;

void how() {
    F(i,0,N) F(j,0,N) Ans.ar[i][j]=0;
    F(i,0,N) Ans.ar[0][0]=1;
}
Matrix Makebase(int p,LL n) {
    Matrix base;
    F(i,0,N) F(j,0,N) base.ar[i][j]=0;
    for(int i=0;i<=c[p];i++) {
        for(int j=-1;j<=1;j++) {
            int ps=i+j;
            if(ps>=0&&ps<=(c[p])) {
                base.ar[i][ps]=1;
            }
        }
    }
    return Big_Mod(base,n);
}

void lol(int p) {
    LL l=a[p],r=b[p];
    LL gap=r-l;
    Matrix nw=Makebase(p,gap);
    Ans=MUL(nw,Ans);
}

int main(){

    how();
    LL n,k;
    cin>>n>>k;

    F(i,1,n+1) {
        cin>>a[i]>>b[i]>>c[i];
    }
    b[n]=k;
    F(i,1,n+1) {
        lol(i);
    }
    cout<<Ans.ar[0][0]<<endl;

    return 0;
}
///============= Thank You ===================///


/********************************************
*                                           *
*    Solved By : Bir Bahadur Khatri(B'ru)   *
*      Be Positive,be Happy.                *
*                                           *
*********************************************/
#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define MP make_pair
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#include<bits/stdc++.h>
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define LL long long int
#define S1(a) a=in<int>()
#define SL1(a) a=in<LL>()
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define S2(a,b) a=in<int>(),b=in<int>()
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define _cin ios_base::sync_with_stdio(0); cin.tie(0)
#define cp printf("***** here here here here *****\n");
#define trace1(x)                cerr << #x << ": " << x << endl;
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
template <typename T> LL isLeft(T a,T b,T c) {return(a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y);}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
///**********************************************************//

#define MD1 1000000007ULL
#define MD2 1000000009ULL
#define MD3 1000000021ULL
#define BS1 10000019ULL
#define BS2 10000079ULL
#define BS3 10000103ULL
#define PUL pair<ULL,ULL>
#define PLL pair<LL,LL>
#define PII pair<int,int>

#define lchild lft,l,mid
#define rchild rgt,mid+1,r
#define ngood  r<st||l>ed
#define good   st<=l&&ed>=r
#define seg    int mid=(l+r)/2,lft=2*id,rgt=lft+1

///         0123456789
#define MX  500007
#define MOD 1000000007
#define INF 2000000000000000LL
#define EPS 1e-9

/// ==========================================////

struct Matrix {
    LL ar[16][16];
};

const int N=16;

Matrix MUL(Matrix a,Matrix b) {
    Matrix ans;
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            ans.ar[i][j]=0;
            for(int k=0;k<N;k++) {
                ans.ar[i][j]=(ans.ar[i][j]+a.ar[i][k]*b.ar[k][j])%MOD;
            }
        }
    }
    return ans;
}

Matrix Big_Mod(Matrix a,LL n) {
    Matrix ans=a;
    n--;
    while(n) {
        if(n&1) {
            ans=MUL(ans,a);
        }
        a=MUL(a,a);
        n/=2;
    }
    return ans;
}

LL a[MX];
LL b[MX];
LL c[MX];
Matrix Makebase(int p,LL n) {
    Matrix base;
    F(i,0,N) F(j,0,N) base.ar[i][j]=0;
    for(int i=0;i<=c[p];i++) {
        for(int j=-1;j<=1;j++) {
            int ps=i+j;
            if(ps>=0) {
                base.ar[i][ps]=1;
            }
        }
    }
    return Big_Mod(base,n);
}

vector<LL> lol(vector<LL> v,int p) {

    vector<LL> vv;
    F(i,0,N) {
        if(i<=p) vv.PB(v[i]);
        else vv.PB(0);
    }
    v=vv;
    LL l=a[p],r=b[p],ps=c[p];
    LL gap=r-l;
    Matrix nw=Makebase(p,gap);
    vector<LL> ans;
    for(int i=0;i<N;i++) {
        LL an=0;
        F(j,0,N) {
            an=(an+v[j]*nw.ar[i][j])%MOD;
        }
        ans.PB(an);
    }
    return ans;
}

int main(){

    LL n,k;
    cin>>n>>k;

    F(i,1,n+1) {
        cin>>a[i]>>b[i]>>c[i];
    }
    b[n]=k;
    vector<LL> v;
    v.PB(1);
    F(i,1,16) {
        v.PB(0);
    }

    F(i,1,n+1) {
        v=lol(v,i);
    }
    cout<<v[0]<<endl;

    return 0;
}
///============= Thank You ===================///


/********************************************
*                                           *
*    Solved By : Bir Bahadur Khatri(B'ru)   *
*      Be Positive,be Happy.                *
*                                           *
*********************************************/
#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define MP make_pair
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#include<bits/stdc++.h>
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define LL long long int
#define S1(a) a=in<int>()
#define SL1(a) a=in<LL>()
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define S2(a,b) a=in<int>(),b=in<int>()
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define _cin ios_base::sync_with_stdio(0); cin.tie(0)
#define cp printf("***** here here here here *****\n");
#define trace1(x)                cerr << #x << ": " << x << endl;
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
template <typename T> LL isLeft(T a,T b,T c) {return(a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y);}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
///**********************************************************//

#define MD1 1000000007ULL
#define MD2 1000000009ULL
#define MD3 1000000021ULL
#define BS1 10000019ULL
#define BS2 10000079ULL
#define BS3 10000103ULL
#define PUL pair<ULL,ULL>
#define PLL pair<LL,LL>
#define PII pair<int,int>

#define lchild lft,l,mid
#define rchild rgt,mid+1,r
#define ngood  r<st||l>ed
#define good   st<=l&&ed>=r
#define seg    int mid=(l+r)/2,lft=2*id,rgt=lft+1

///         0123456789
#define MX  500007
#define MOD 1000000007
#define INF 2000000000000000LL
#define EPS 1e-9

/// ==========================================////

struct Matrix {
    LL ar[16][16];
};

const int N=16;

Matrix MUL(Matrix a,Matrix b) {
    Matrix ans;
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            ans.ar[i][j]=0;
            for(int k=0;k<N;k++) {
                ans.ar[i][j]=(ans.ar[i][j]+a.ar[i][k]*b.ar[k][j])%MOD;
            }
        }
    }
    return ans;
}

Matrix Big_Mod(Matrix a,LL n) {
    Matrix ans=a;
    n--;
    while(n) {
        if(n&1) {
            ans=MUL(ans,a);
        }
        a=MUL(a,a);
        n/=2;
    }
    return ans;
}

LL a[MX];
LL b[MX];
LL c[MX];
Matrix Makebase(int p,LL n) {
    Matrix base;
    F(i,0,N) F(j,0,N) base.ar[i][j]=0;
    for(int i=0;i<=c[p];i++) {
        for(int j=-1;j<=1;j++) {
            int ps=i+j;
            if(ps>=0&&ps<=c[p]) {
                base.ar[i][ps]=1;
            }
        }
    }
    return Big_Mod(base,n);
}

vector<LL> lol(vector<LL> v,int p) {

    vector<LL> vv;
    F(i,0,N) {
        if(i<=c[p]) vv.PB(v[i]);
        else vv.PB(0);
    }
    v=vv;
    LL l=a[p],r=b[p],ps=c[p];
    LL gap=r-l;
    Matrix nw=Makebase(p,gap);
    vector<LL> ans;
    for(int i=0;i<N;i++) {
        LL an=0;
        F(j,0,N) {
            an=(an+v[j]*nw.ar[i][j])%MOD;
        }
        ans.PB(an);
    }
    return ans;
}

int main(){

    LL n,k;
    cin>>n>>k;

    F(i,1,n+1) {
        cin>>a[i]>>b[i]>>c[i];
    }
    if(a[n]==k) n--;
    b[n]=k;
    vector<LL> v;
    v.PB(1);
    F(i,1,16) {
        v.PB(0);
    }

    F(i,1,n+1) {
        v=lol(v,i);
    }
    cout<<v[0]<<endl;

    return 0;
}
///============= Thank You ===================///


/********************************************
*                                           *
*    Solved By : Bir Bahadur Khatri(B'ru)   *
*      Be Positive,be Happy.                *
*                                           *
*********************************************/
#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define MP make_pair
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#include<bits/stdc++.h>
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define LL long long int
#define S1(a) a=in<int>()
#define SL1(a) a=in<LL>()
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define S2(a,b) a=in<int>(),b=in<int>()
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define _cin ios_base::sync_with_stdio(0); cin.tie(0)
#define cp printf("***** here here here here *****\n");
#define trace1(x)                cerr << #x << ": " << x << endl;
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
template <typename T> LL isLeft(T a,T b,T c) {return(a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y);}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
///**********************************************************//

#define MD1 1000000007ULL
#define MD2 1000000009ULL
#define MD3 1000000021ULL
#define BS1 10000019ULL
#define BS2 10000079ULL
#define BS3 10000103ULL
#define PUL pair<ULL,ULL>
#define PLL pair<LL,LL>
#define PII pair<int,int>

#define lchild lft,l,mid
#define rchild rgt,mid+1,r
#define ngood  r<st||l>ed
#define good   st<=l&&ed>=r
#define seg    int mid=(l+r)/2,lft=2*id,rgt=lft+1

///         0123456789
#define MX  500007
#define MOD 1000000007
#define INF 2000000000000000LL
#define EPS 1e-9

/// ==========================================////

struct Matrix {
    LL ar[16][16];
};

const int N=16;

Matrix MUL(Matrix a,Matrix b) {
    Matrix ans;
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            ans.ar[i][j]=0;
            for(int k=0;k<N;k++) {
                ans.ar[i][j]=(ans.ar[i][j]+a.ar[i][k]*b.ar[k][j])%MOD;
            }
        }
    }
    return ans;
}

Matrix Big_Mod(Matrix a,LL n) {
    Matrix ans=a;
    n--;
    while(n) {
        if(n&1) {
            ans=MUL(ans,a);
        }
        a=MUL(a,a);
        n/=2;
    }
    return ans;
}

LL a[MX];
LL b[MX];
LL c[MX];
Matrix Ans;

void how() {
    F(i,0,N) F(j,0,N) Ans.ar[i][j]=0;
    F(i,0,N) Ans.ar[0][0]=1;
}
Matrix Makebase(int p,LL n) {
    Matrix base;
    F(i,0,N) F(j,0,N) base.ar[i][j]=0;
    for(int i=0;i<=c[p];i++) {
        for(int j=-1;j<=1;j++) {
            int ps=i+j;
            if(ps>=0&&ps<=c[p]) {
                base.ar[i][ps]=1;
            }
        }
    }
    return Big_Mod(base,n);
}

void Prt(Matrix a) {
    F(i,0,N){
        F(j,0,N) cout<<a.ar[i][j]<< " "; NL;
    }
}

vector<LL> lol(vector<LL> v,int p) {

    vector<LL> vv;
    F(i,0,N) {
        if(i<=c[p]) vv.PB(v[i]);
        else vv.PB(0);
    }
    v=vv;
    LL l=a[p],r=b[p];
    LL gap=r-l;
    Matrix nw=Makebase(p,gap);
    Ans=MUL(Ans,nw);
//    Prt(nw); NL;

    vector<LL> ans;
    for(int i=0;i<N;i++) {
        LL an=0;
        F(j,0,N) {
            an=(an+v[j]*nw.ar[i][j])%MOD;
        }
        ans.PB(an);
    }
    return ans;
}

int main(){

    how();
    LL n,k;
    cin>>n>>k;

    F(i,1,n+1) {
        cin>>a[i]>>b[i]>>c[i];
    }
    b[n]=k;
    vector<LL> v;
    v.PB(1);
    F(i,1,N) {
        v.PB(0);
    }

    F(i,1,n+1) {
        v=lol(v,i);
    }
    cout<<Ans.ar[0][0]<<endl;

    return 0;
}
///============= Thank You ===================///


/********************************************
*                                           *
*    Solved By : Bir Bahadur Khatri(B'ru)   *
*      Be Positive,be Happy.                *
*                                           *
*********************************************/
#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define MP make_pair
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#include<bits/stdc++.h>
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define LL long long int
#define S1(a) a=in<int>()
#define SL1(a) a=in<LL>()
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define S2(a,b) a=in<int>(),b=in<int>()
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define _cin ios_base::sync_with_stdio(0); cin.tie(0)
#define cp printf("***** here here here here *****\n");
#define trace1(x)                cerr << #x << ": " << x << endl;
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
template <typename T> LL isLeft(T a,T b,T c) {return(a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y);}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
///**********************************************************//

#define MD1 1000000007ULL
#define MD2 1000000009ULL
#define MD3 1000000021ULL
#define BS1 10000019ULL
#define BS2 10000079ULL
#define BS3 10000103ULL
#define PUL pair<ULL,ULL>
#define PLL pair<LL,LL>
#define PII pair<int,int>

#define lchild lft,l,mid
#define rchild rgt,mid+1,r
#define ngood  r<st||l>ed
#define good   st<=l&&ed>=r
#define seg    int mid=(l+r)/2,lft=2*id,rgt=lft+1

///         0123456789
#define MX  500007
#define MOD 1000000007
#define INF 2000000000000000LL
#define EPS 1e-9

/// ==========================================////

struct Matrix {
    LL ar[16][16];
};

const int N=16;

Matrix MUL(Matrix a,Matrix b) {
    Matrix ans;
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            ans.ar[i][j]=0;
            for(int k=0;k<N;k++) {
                ans.ar[i][j]=(ans.ar[i][j]+a.ar[i][k]*b.ar[k][j])%MOD;
            }
        }
    }
    return ans;
}

Matrix Big_Mod(Matrix a,LL n) {
    Matrix ans=a;
    n--;
    while(n) {
        if(n&1) {
            ans=MUL(ans,a);
        }
        a=MUL(a,a);
        n/=2;
    }
    return ans;
}

LL a[MX];
LL b[MX];
LL c[MX];
Matrix Makebase(int p,LL n) {
    Matrix base;
    F(i,0,N) F(j,0,N) base.ar[i][j]=0;
    for(int i=0;i<=c[p];i++) {
        for(int j=-1;j<=1;j++) {
            int ps=i+j;
            if(ps>=0) {
                base.ar[i][ps]=1;
            }
        }
    }
    return Big_Mod(base,n);
}

void Prt(Matrix a) {
    F(i,0,N){
        F(j,0,N) cout<<a.ar[i][j]<< " "; NL;
    }
}

vector<LL> lol(vector<LL> v,int p) {

    vector<LL> vv;
    F(i,0,N) {
        if(i<=c[p]) vv.PB(v[i]);
        else vv.PB(0);
    }
    v=vv;
    LL l=a[p],r=b[p],ps=c[p];
    LL gap=r-l;
    Matrix nw=Makebase(p,gap);

//    Prt(nw); NL;

    vector<LL> ans;
    for(int i=0;i<N;i++) {
        LL an=0;
        F(j,0,N) {
            an=(an+v[j]*nw.ar[i][j])%MOD;
        }
        ans.PB(an);
    }
    return ans;
}

int main(){

    LL n,k;
    cin>>n>>k;

    F(i,1,n+1) {
        cin>>a[i]>>b[i]>>c[i];
    }
    b[n]=k;
    vector<LL> v;
    v.PB(1);
    F(i,1,N) {
        v.PB(0);
    }

    F(i,1,n+1) {
        v=lol(v,i);
    }
    cout<<v[0]<<endl;

    return 0;
}
///============= Thank You ===================///


/********************************************
*                                           *
*    Solved By : Bir Bahadur Khatri(B'ru)   *
*      Be Positive,be Happy.                *
*                                           *
*********************************************/
#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define MP make_pair
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#include<bits/stdc++.h>
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define LL long long int
#define S1(a) a=in<int>()
#define SL1(a) a=in<LL>()
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define S2(a,b) a=in<int>(),b=in<int>()
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define _cin ios_base::sync_with_stdio(0); cin.tie(0)
#define cp printf("***** here here here here *****\n");
#define trace1(x)                cerr << #x << ": " << x << endl;
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
template <typename T> LL isLeft(T a,T b,T c) {return(a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y);}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
///**********************************************************//

#define MD1 1000000007ULL
#define MD2 1000000009ULL
#define MD3 1000000021ULL
#define BS1 10000019ULL
#define BS2 10000079ULL
#define BS3 10000103ULL
#define PUL pair<ULL,ULL>
#define PLL pair<LL,LL>
#define PII pair<int,int>

#define lchild lft,l,mid
#define rchild rgt,mid+1,r
#define ngood  r<st||l>ed
#define good   st<=l&&ed>=r
#define seg    int mid=(l+r)/2,lft=2*id,rgt=lft+1

///         0123456789
#define MX  500007
#define MOD 1000000007
#define INF 2000000000000000LL
#define EPS 1e-9

/// ==========================================////

struct Matrix {
    LL ar[16][16];
};

const int N=16;

Matrix MUL(Matrix a,Matrix b) {
    Matrix ans;
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            ans.ar[i][j]=0;
            for(int k=0;k<N;k++) {
                ans.ar[i][j]=(ans.ar[i][j]+a.ar[i][k]*b.ar[k][j])%MOD;
            }
        }
    }
    return ans;
}

Matrix Big_Mod(Matrix a,LL n) {
    Matrix ans=a;
    n--;
    while(n) {
        if(n&1) {
            ans=MUL(ans,a);
        }
        a=MUL(a,a);
        n/=2;
    }
    return ans;
}

LL a[MX];
LL b[MX];
LL c[MX];
Matrix Makebase(int p,LL n) {
    Matrix base;
    F(i,0,N) F(j,0,N) base.ar[i][j]=0;
    for(int i=0;i<=c[p];i++) {
        for(int j=-1;j<=1;j++) {
            int ps=i+j;
            if(ps>=0&&ps<=p) {
                base.ar[i][ps]=1;
            }
        }
    }
    return Big_Mod(base,n);
}

vector<LL> lol(vector<LL> v,int p) {

    vector<LL> vv;
    F(i,0,N) {
        if(i<=p) vv.PB(v[i]);
        else vv.PB(0);
    }
    v=vv;
    LL l=a[p],r=b[p],ps=c[p];
    LL gap=r-l;
    Matrix nw=Makebase(p,gap);
    vector<LL> ans;
    for(int i=0;i<N;i++) {
        LL an=0;
        F(j,0,N) {
            an=(an+v[j]*nw.ar[i][j])%MOD;
        }
        ans.PB(an);
    }
    return ans;
}

int main(){

    LL n,k;
    cin>>n>>k;

    F(i,1,n+1) {
        cin>>a[i]>>b[i]>>c[i];
    }
    b[n]=k;
    vector<LL> v;
    v.PB(1);
    F(i,1,16) {
        v.PB(0);
    }

    F(i,1,n+1) {
        v=lol(v,i);
    }
    cout<<v[0]<<endl;

    return 0;
}
///============= Thank You ===================///


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a%=mod;b%=mod;
	a += b;
	a %= mod;
	//if(a >= mod) a -= b;
}
int mul(int a, int b){
	ll ret = 1ll * a * b;
	ret %= mod;
	return ret;
}// return int((1ll*a*b)%mod); }
struct MAT{
	int a[N+1][N+1];
	MAT(){ cl(a); }
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N)rep(j,0,N)rep(k,0,N) add(ret.a[i][j],mul(a[i][k],ot.a[k][j]));
		return ret;
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a += b;
	if(a >= mod) a -= b;
}
int mul(int a, int b){
	ll ret = 1ll * a * b;
	ret %= mod;
	return ret;
}// return int((1ll*a*b)%mod); }
struct MAT{
	int a[N+1][N+1];
	MAT(){ cl(a); }
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N)rep(j,0,N)rep(k,0,N){
			ll ad = mul(a[i][k],ot.a[k][j]);
			ret.a[i][j] += ad;
			ret.a[i][j] %= mod;

		}//ll ad = mul(a[i][])
			//add(ret.a[i][j],mul(a[i][k],ot.a[k][j]));
		return ret;
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a += b;
	if(a >= mod) a -= b;
}
int mul(int a, int b){
	ll ret = 1ll * a * b;
	ret %= mod;
	return ret;
}// return int((1ll*a*b)%mod); }
struct MAT{
	int a[N+1][N+1];
	MAT(){ cl(a); }
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N)rep(j,0,N)rep(k,0,N) //ll ad = mul(a[i][])
			add(ret.a[i][j],mul(a[i][k],ot.a[k][j]));
		return ret;
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a += b;
	if(a >= mod) a -= b;
}
int mul(int a, int b){
	ll ret = 1ll * a * b;
	ret %= mod;
	return ret;
}// return int((1ll*a*b)%mod); }
struct MAT{
	int a[N+1][N+1];
	MAT(){ cl(a); }
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N)rep(j,0,N)rep(k,0,N){

			ll ad = mul(a[i][k],ot.a[k][j]);
			ad %= mod;
			ret.a[i][j] += (int)ad;
			ret.a[i][j] %= mod;
		}//add(ret.a[i][j],mul(a[i][k],ot.a[k][j]));
		return ret;
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a%=mod;b%=mod;
	a += b;
	if(a >= mod) a -= b;
}
int mul(int a, int b){
	ll ret = 1ll * a * b;
	ret %= mod;
	return ret;
}// return int((1ll*a*b)%mod); }
struct MAT{
	int a[N+1][N+1];
	MAT(){ cl(a); }
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N)rep(j,0,N)rep(k,0,N) add(ret.a[i][j],mul(a[i][k],ot.a[k][j]));
		return ret;
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a += b;
	if(a >= mod) a -= b;
}
int mul(int a, int b){
	ll ret = 1ll * a * b;
	ret %= mod;
	return ret;
}// return int((1ll*a*b)%mod); }
struct MAT{
	int a[N+1][N+1];
	MAT(){ cl(a); }
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N)rep(j,0,N)rep(k,0,N)add(ret.a[i][j],mul(a[i][k],ot.a[k][j]));
		return ret;
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a += b;
	if(a > mod) a -= b;
}
int mul(int a, int b){
	ll ret = 1ll * a * b;
	ret %= mod;
	return (int)ret;
}
struct MAT{
	int a[N+5][N+5];
	MAT(){
		cl(a);
	}
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N) rep(j,0,N) rep(k,0,N){
			ll ad = a[i][k] * ot.a[k][j];
			if(ad){
				ret.a[i][j] += ad;
				if(ret.a[i][j] >= mod)
					ret.a[i][j] %= mod;
			}
		}
		return ret;
	}
	void output(){
		rep(i,0,N){
			rep(j,0,N){
				printf("%d ",a[i][j]);
			}
			puts("");
		}
		puts("");
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
#ifdef HandsomeHow
	freopen("E.in","r",stdin);
	//freopen("data.out","w",stdout);
#endif
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		dbg(dis);
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a%=mod;b%=mod;
	a += b;
	if(a >= mod) a -= mod;
}
int mul(int a, int b){ return int((1ll*a*b)%mod); }
struct MAT{
	int a[N+1][N+1];
	MAT(){ cl(a); }
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N)rep(k,0,N)if(a[i][k])rep(j,0,N)add(ret.a[i][j],mul(a[i][k],ot.a[k][j]));
		return ret;
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a += b;
	if(a >= mod) a -= b;
}
int mul(int a, int b){ return int((1ll*a*b)%mod); }
struct MAT{
	int a[N+1][N+1];
	MAT(){ cl(a); }
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N)rep(j,0,N)rep(k,0,N)add(ret.a[i][j],mul(a[i][k],ot.a[k][j]));
		return ret;
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a += b;
	if(a >= mod) a -= b;
}
int mul(int a, int b){ return int((1ll*a*b)%mod); }
struct MAT{
	int a[N+1][N+1];
	MAT(){ cl(a); }
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N)rep(k,0,N)if(a[i][k])rep(j,0,N)add(ret.a[i][j],mul(a[i][k],ot.a[k][j]));
		return ret;
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a += b;
	if(a > mod) a -= b;
}
int mul(int a, int b){
	ll ret = 1ll * a * b;
	ret %= mod;
	return (int)ret;
}
struct MAT{
	int a[N+5][N+5];
	MAT(){
		cl(a);
	}
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N) rep(j,0,N) rep(k,0,N){
			ll ad = 1ll * a[i][k] * ot.a[k][j];
			ad %= mod;
			if(ad){
				ret.a[i][j] += ad;
				if(ret.a[i][j] >= mod)
					ret.a[i][j] %= mod;
			}
		}
		return ret;
	}
	void output(){
		rep(i,0,N){
			rep(j,0,N){
				printf("%d ",a[i][j]);
			}
			puts("");
		}
		puts("");
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
#ifdef HandsomeHow
	freopen("E.in","r",stdin);
	//freopen("data.out","w",stdout);
#endif
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		dbg(dis);
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a += b;
	if(a >= mod) a -= b;
}
int mul(int a, int b){
	ll ret = 1ll * a * b;
	ret %= mod;
	return ret;
}// return int((1ll*a*b)%mod); }
struct MAT{
	int a[N+1][N+1];
	MAT(){ cl(a); }
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N)rep(j,0,N)rep(k,0,N){
			ll ad = mul(a[i][j],ot.a[k][j]);
			ret.a[i][j] += ad;
			ret.a[i][j] %= mod;

		}//ll ad = mul(a[i][])
			//add(ret.a[i][j],mul(a[i][k],ot.a[k][j]));
		return ret;
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a%=mod;b%=mod;
	a += b;
	if(a >= mod) a -= mod;
}
int mul(int a, int b){ return int((1ll*a*b)%mod); }
struct MAT{
	int a[N+1][N+1];
	MAT(){ cl(a); }
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N)rep(j,0,N)rep(k,0,N) add(ret.a[i][j],mul(a[i][k],ot.a[k][j]));
		return ret;
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
const int N = 15;
void add(int &a, int b){
	a += b;
	if(a >= mod) a -= b;
}
int mul(int a, int b){ return int((1ll*a*b)%mod); }
struct MAT{
	int a[N+1][N+1];
	MAT(){ cl(a); }
	MAT operator*(const MAT& ot){
		MAT ret;
		rep(i,0,N)rep(k,0,N)rep(j,0,N)add(ret.a[i][j],mul(a[i][k],ot.a[k][j]));
		return ret;
	}
};
MAT powmat(MAT a, ll b){
	MAT ret;
	rep(i,0,N)ret.a[i][i]=1;
	while(b){
		if(b&1)ret=ret*a;
		b>>=1;
		a=a*a;
	}
	return ret;
}
int main(){
	int n; ll k;
	gn(n);gn(k);
	MAT ans;
	ans.a[0][0]=1;
	while(n--){
		ll A, B; int c;
		gn(A);gn(B);gn(c);
		if(A > k) A = k;
		if(B > k) B = k;
		ll dis = B - A;
		MAT b;
		rep(i,0,c){
			b.a[i][i]=1;
			if(i-1>=0)b.a[i-1][i]=1;
			if(i+1<=c)b.a[i+1][i]=1;
		}
		ans = ans * powmat(b,dis);
	}
	cout<<ans.a[0][0]<<endl;
	return 0;
}


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

///priority_queue< int, vector< int >, greater< int > > minHeap;

#define M 20

int m;

struct Matrix
{
    int a[M][M];

    Matrix()
    {
        Fill(a,0);
    }

    Matrix operator*(const Matrix &b)
    {
        Matrix ret;

        for(int i=0; i<m; i++)
        {

            for(int j=0; j<m; j++)
            {

                lli sum = 0;

                for(int k=0; k<m; k++)
                {

                    sum = (sum + (a[i][k]*1LL*b.a[k][j])) % mod;
                }

                ret.a[i][j] = sum;
            }
        }
        return ret;
    }
} mul,I;

Matrix Mpow(lli n)
{

    Matrix ret = I; /// identity matrix

    while(n)
    {

        if(n%2) ret = ret*mul;

        n >>= 1;
        mul = mul*mul;
    }

    return ret;
}

void Init(){

    for(int i=0; i<m; i++)
    {
        mul.a[i][i] = 1;

        if((i-1) >= 0) mul.a[i][i-1] = 1;

        if((i+1) < m) mul.a[i][i+1] = 1;
    }
}

int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    ///FastIO;
    int n;
    lli k;
    cin>>n>>k;
    lli ans = 1;

    vector<lli>last(20,0);
    last[15] = 1;

    m = 16;
    for(int i=0; i<m; i++) I.a[i][i] = 1;

    while(n--)
    {
        lli a,b;
        int c;
        scn2ll(a,b);
        scn(c);

        vector<lli>now(20,0);

        Init();

        for(int i=0; i<m-c-1; i++){
            for(int j=0; j<m; j++) mul.a[i][j] = 0;
        }

        if((m-c-2)>=0) mul.a[m-c-1][m-c-2] = 0;

        Matrix then;
        b = min(b,k);
        then = Mpow(b-a);

        for(int i=m-c-1; i<m; i++){

            now[i] = (then.a[i][i]*last[i])%mod;

            if((i+1)<m) now[i] = (now[i] + (then.a[i][i+1]*last[i+1])%mod ) % mod;

            if((i-1)>=(m-c-1)) now[i] = (now[i] + (then.a[i][i-1]*last[i-1])%mod ) % mod;
        }
        last = now;
      // for(int i=0; i<m; i++)cout<<last[i]<<" -- ";
        //cout<<endl;
    }

    cout<<last[15];

    return 0;
    ///return main();
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

///priority_queue< int, vector< int >, greater< int > > minHeap;

#define M 20

int m;

struct Matrix
{
    int a[M][M];

    Matrix()
    {
        Fill(a,0);
    }

    Matrix operator*(const Matrix &b)
    {
        Matrix ret;

        for(int i=0; i<m; i++)
        {

            for(int j=0; j<m; j++)
            {

                lli sum = 0;

                for(int k=0; k<m; k++)
                {

                    sum = (sum + (a[i][k]*1LL*b.a[k][j])) % mod;
                }

                ret.a[i][j] = sum;
            }
        }
        return ret;
    }
} mul,I;

Matrix Mpow(lli n)
{

    Matrix ret = I; /// identity matrix

    while(n)
    {

        if(n%2) ret = ret*mul;

        n >>= 1;
        mul = mul*mul;
    }

    return ret;
}

void Init(){

    for(int i=0; i<m; i++)
    {
        mul.a[i][i] = 1;

        if((i-1) >= 0) mul.a[i][i-1] = 1;

        if((i+1) < m) mul.a[i][i+1] = 1;
    }
}

int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    ///FastIO;
    int n;
    lli k;
    cin>>n>>k;
    lli ans = 1;

    vector<lli>last(20,0);
    last[15] = 1;

    m = 16;
    for(int i=0; i<m; i++) I.a[i][i] = 1;

    while(n--)
    {
        lli a,b;
        int c;
        scn2ll(a,b);
        scn(c);

        if(c==0){
            for(int i=0; i<m-1; i++)last[i] = 0;
            continue;
        }

        vector<lli>now(20,0);

        Init();

        for(int i=0; i<m-c-1; i++){
            for(int j=0; j<m; j++) mul.a[i][j] = 0;
        }

        if((m-c-2)>=0) mul.a[m-c-1][m-c-2] = 0;

        Matrix then;
        b = min(b,k);
        then = Mpow(b-a);

        for(int i=m-c-1; i<m; i++){

            now[i] = (then.a[i][i]*last[i])%mod;

            if((i+1)<m) now[i] = (now[i] + (then.a[i][i+1]*last[i+1])%mod ) % mod;

            if((i-1)>=(m-c-1)) now[i] = (now[i] + (then.a[i][i-1]*last[i-1])%mod ) % mod;
        }
        last = now;
      // for(int i=0; i<m; i++)cout<<last[i]<<" -- ";
        //cout<<endl;
    }

    cout<<last[15];

    return 0;
    ///return main();
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)