#include <bits/stdc++.h>
using namespace std;
const long long P = 1e9 + 7;
const int INF = 0x3fffffff;
const int N = 1E6 + 5;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct mat {
  const static int K = 70;
  int m[K][K], n;
  mat(int n = K - 1) {
    this->n = n;
    memset(m, 0, sizeof m);
  }
  void setI() {
    for (int i = (1); i <= (n); ++i) m[i][i] = 1;
  }
  mat operator*(mat b) {
    mat res(n);
    for (int k = (1); k <= (n); ++k)
      for (int i = (1); i <= (n); ++i)
        for (int j = (1); j <= (n); ++j)
          res.m[i][j] = (res.m[i][j] + 1ll * m[i][k] * b.m[k][j]) % P;
    return res;
  }
  mat operator*(int b) {
    mat res;
    for (int i = (1); i <= (n); ++i)
      for (int j = (1); j <= (n); ++j) res.m[i][j] = 1ll * m[i][j] * b % P;
    return res;
  }
  mat operator+(mat b) {
    mat res;
    for (int i = (1); i <= (n); ++i)
      for (int j = (1); j <= (n); ++j)
        res.m[i][j] = 1ll * (m[i][j] + b.m[i][j]) % P;
    return res;
  }
};
long long n, k, x, y, z, f[50], g[50];
mat pw(mat x, long long n) {
  mat res(x.n);
  res.setI();
  for (; n; n >>= 1, x = x * x)
    if (n & 1) res = res * x;
  return res;
}
int main() {
  cin >> n >> k;
  int pz = 1;
  f[1] = 1;
  for (int i = (1); i <= (n); ++i) {
    cin >> x >> y >> z;
    y = min(y, k), ++z;
    mat a(z);
    for (int i = (1); i <= (z); ++i)
      for (int j = (i - 1); j <= (i + 1); ++j)
        if (j && j <= z) {
          a.m[i][j] = 1;
        }
    a = pw(a, y - x);
    swap(f, g);
    memset(f, 0, sizeof f);
    for (int i = (1); i <= (z); ++i)
      for (int j = (1); j <= (z); ++j) {
        (f[i] += a.m[i][j] * g[j]) %= P;
      }
    pz = z;
  }
  cout << f[1] << endl;
  return 0;
}
