#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
int n;
long long ans[16] = {1}, k;
struct matrix {
  int h, l;
  long long a[16][16];
} x, y, z;
matrix operator*(const matrix &a, const matrix &b) {
  matrix res;
  res.h = a.h, res.l = b.l;
  for (int i = 0; i <= a.h; ++i) {
    for (int j = 0; j <= b.l; ++j) {
      res.a[i][j] = 0;
      for (int k = 0; k <= a.l; ++k)
        (res.a[i][j] += a.a[i][k] * b.a[k][j]) %= 1000000007;
    }
  }
  return res;
}
matrix q_pow(matrix x, long long y) {
  matrix res;
  res.h = x.h, res.l = x.l;
  for (int i = 0; i <= res.h; ++i)
    for (int j = 0; j <= res.h; ++j) res.a[i][j] = (i == j);
  while (y) {
    if (y & 1) res = res * x;
    x = x * x;
    y >>= 1;
  }
  return res;
}
int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; ++i) {
    long long a = read(), b = read();
    int c = read();
    if (i == n) b = k;
    for (int j = c + 1; j < 16; ++j) ans[j] = 0;
    x.h = 0, x.l = c;
    for (int j = 0; j <= c; ++j) x.a[0][j] = ans[j];
    y.h = c, y.l = c;
    for (int j = 0; j <= c; ++j)
      for (int k = 0; k <= c; ++k) y.a[j][k] = (abs(j - k) < 2);
    z = q_pow(y, b - a);
    z = x * q_pow(y, b - a);
    for (int j = 0; j <= c; ++j) ans[j] = z.a[0][j];
  }
  printf("%lld\n", ans[0]);
  return 0;
}
