#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n, i, j;
long long k, dp[25], pre[25];
vector<vector<long long>> coef, iden;
vector<vector<long long>> mul(vector<vector<long long>> a,
                              vector<vector<long long>> b) {
  vector<vector<long long>> c;
  int siz = a.size();
  for (int ii = 0; ii < siz; ii++) {
    vector<long long> tmp;
    for (int jj = 0; jj < siz; jj++) tmp.push_back(0);
    c.push_back(tmp);
  }
  for (int ii = 0; ii < siz; ii++) {
    for (int jj = 0; jj < siz; jj++) {
      for (int kk = 0; kk < siz; kk++) {
        c[ii][jj] = (c[ii][jj] + a[ii][kk] * b[kk][jj]) % MOD;
      }
    }
  }
  return c;
}
vector<vector<long long>> mypow(vector<vector<long long>> a, long long lv) {
  if (lv == 0) return iden;
  vector<vector<long long>> tmp = mypow(a, lv / 2);
  tmp = mul(tmp, tmp);
  if (lv & 1) tmp = mul(tmp, a);
  return tmp;
}
int main() {
  scanf("%d%lld", &n, &k);
  pre[0] = 1;
  for (i = 0; i < n; i++) {
    long long x, y;
    int z;
    scanf("%lld%lld%d", &x, &y, &z);
    y = min(y, k);
    coef.clear();
    iden.clear();
    for (j = 0; j <= z; j++) {
      vector<long long> tmp;
      vector<long long> tmp1;
      for (int ii = 0; ii <= z; ii++) {
        tmp.push_back(0);
        if (j == ii)
          tmp1.push_back(1);
        else
          tmp1.push_back(0);
      }
      coef.push_back(tmp);
      iden.push_back(tmp1);
    }
    for (j = 0; j <= z; j++) {
      for (int ii = 0; ii <= z; ii++) {
        if (ii == j || ii == j - 1 || ii == j + 1)
          coef[ii][j] = 1;
        else
          coef[ii][j] = 0;
      }
    }
    coef = mypow(coef, y - x);
    memset(dp, 0, sizeof(dp));
    for (j = 0; j <= z; j++) {
      for (int ii = 0; ii <= z; ii++)
        dp[j] = (dp[j] + pre[ii] * coef[ii][j]) % MOD;
    }
    memset(pre, 0, sizeof(pre));
    for (j = 0; j <= z; j++) pre[j] = dp[j];
  }
  printf("%lld\n", pre[0]);
}
