#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, c;
long long k;
struct Matrix {
  int a[17][17], n, m;
  Matrix() { memset(a, 0, sizeof a); }
  Matrix operator*(const Matrix &t) {
    Matrix r;
    r.n = n;
    r.m = t.m;
    for (int i = 1; i <= r.n; ++i)
      for (int j = 1; j <= r.m; ++j)
        if (a[i][j])
          for (int k = 1; k <= m; ++k)
            r.a[i][k] = (r.a[i][k] + 1ll * a[i][j] * t.a[j][k] % mod) % mod;
    return r;
  }
} A, x;
queue<int> q;
long long read() {
  long long x = 0, f = 1;
  char s;
  while ((s = getchar()) > '9' || s < '0')
    if (s == '-') f = -1;
  while (s >= '0' && s <= '9')
    x = (x << 1) + (x << 3) + (s ^ 48), s = getchar();
  return x * f;
}
Matrix qkpow(long long y) {
  Matrix r;
  r.n = r.m = c;
  for (int i = 1; i <= r.n; ++i) r.a[i][i] = 1;
  while (y) {
    if (y & 1) r = r * x;
    x = x * x;
    y >>= 1;
  }
  return r;
}
int main() {
  long long l, r;
  n = read(), k = read();
  A.a[1][1] = 1;
  for (int i = 1; i <= n; ++i) {
    l = read(), r = read(), c = read() + 1;
    if (l > k) continue;
    r = min(r, k);
    l = r - l;
    for (int j = 1; j <= c; ++j) q.push(A.a[1][j]);
    A = Matrix();
    x = Matrix();
    for (int j = 1; j <= c; ++j) A.a[1][j] = q.front(), q.pop();
    for (int j = 1; j <= c; ++j)
      for (int k = 1; k <= c; ++k)
        if (fabs(j - k) <= 1) x.a[k][j] = 1;
    A.n = 1, A.m = x.n = x.m = c;
    x = qkpow(l);
    A = A * x;
  }
  printf("%d\n", A.a[1][1]);
  return 0;
}
