#include <bits/stdc++.h>
const long long N = 16, mod = 1E9 + 7;
long long n, k, a[N][N], b[N][N], c[N][N], f[N], g[N];
long long read() {
  long long d = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') d = d * 10 + c - 48, c = getchar();
  return d * f;
}
int main() {
  n = read();
  k = read();
  f[0] = 1;
  while (n--) {
    long long x = read(), y = read(), z = read();
    if (y > k) y = k;
    memset(a, 0, sizeof a);
    a[0][0] = a[0][1] = 1;
    a[N - 1][N - 1] = a[N - 1][N - 2] = 1;
    for (int i = 1; i < N - 1; i++) a[i][i - 1] = a[i][i] = a[i][i + 1] = 1;
    for (int i = z + 1; i < N; i++)
      for (int j = 0; j < N; j++) a[i][j] = a[j][i] = 0;
    x = y - x;
    x--;
    memcpy(b, a, sizeof a);
    for (; x; x >>= 1) {
      if (x & 1) {
        memset(c, 0, sizeof c);
        for (int i = 0; i < N; i++)
          for (int j = 0; j < N; j++)
            for (int k = 0; k < N; k++)
              c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % mod;
        memcpy(b, c, sizeof c);
      }
      memset(c, 0, sizeof c);
      for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
          for (int k = 0; k < N; k++)
            c[i][j] = (c[i][j] + a[i][k] * a[k][j]) % mod;
      memcpy(a, c, sizeof c);
    }
    memset(g, 0, sizeof g);
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++) g[i] = (g[i] + f[j] * b[i][j]) % mod;
    memcpy(f, g, sizeof g);
    if (y == k) break;
  }
  printf("%lld", f[0]);
  return 0;
}
