#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e3 + 5;
const double eps = 1e-6;
const int inf = 1e9;
const long long INF = 1e15;
int cas = 1;
int ssize;
long long mat[35][35];
long long aa[maxn], bb[maxn], cc[maxn];
struct Ma {
  long long a[35][35];
  void cc() { memset(a, 0, sizeof(a)); }
  Ma operator*(const Ma &b) const {
    Ma tmp;
    tmp.cc();
    for (int i = 0; i < ssize; i++) {
      for (int j = 0; j < ssize; j++) {
        for (int k = 0; k < ssize; k++) {
          tmp.a[i][j] += (a[i][k] * b.a[k][j]);
          tmp.a[i][j] %= mod;
        }
      }
    }
    return tmp;
  }
} res, x;
void qpow(long long y) {
  while (y) {
    if (y & 1) res = res * x;
    x = x * x;
    y >>= 1;
  }
}
void init() {
  res.cc();
  ssize = 16;
  for (int i = 0; i < ssize; i++) {
    res.a[i][i] = 1;
  }
}
void solve() {
  long long n, kk;
  cin >> n >> kk;
  for (int i = 0; i < n; i++) cin >> aa[i] >> bb[i] >> cc[i];
  init();
  for (int i = 0; i < n; i++) {
    memset(mat, 0, sizeof(mat));
    for (int j = 0; j <= cc[i]; j++) {
      if (j + 1 <= cc[i]) mat[j][j + 1]++;
      if (j - 1 >= 0) mat[j][j - 1]++;
      mat[j][j]++;
    }
    x.cc();
    memcpy(x.a, mat, sizeof(mat));
    if (bb[i] >= kk)
      qpow(kk - aa[i]);
    else
      qpow(bb[i] - aa[i]);
  }
  cout << res.a[0][0] << endl;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
