#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long n;
long long k;
struct mat {
  long long m[17][17];
  void clr() {
    for (long long i = 0; i < 15; i++) {
      for (long long j = 0; j < 15; j++) {
        m[i][j] = 0;
        if (j >= i - 1 && j <= i + 1) {
          m[i][j] = 1;
        }
      }
    }
  }
  void clr2() {
    for (long long i = 0; i < 15; i++) {
      for (long long j = 0; j < 15; j++) {
        m[i][j] = 0;
        if (i == j) m[i][j] = 1;
      }
    }
  }
} A, B, pre;
mat mul(mat A, mat B, long long len) {
  mat C;
  memset(C.m, 0, sizeof(C.m));
  for (int i = 0; i <= len; i++) {
    for (int j = 0; j <= len; j++) {
      for (int k = 0; k <= len; k++) {
        C.m[i][j] = (C.m[i][j] + A.m[i][k] * B.m[k][j]) % mod;
      }
    }
  }
  return C;
}
mat quick_pow(mat A, long long len, int y) {
  mat B;
  memset(B.m, 0, sizeof(B.m));
  for (int i = 0; i <= y; i++) B.m[i][i] = 1;
  while (len) {
    if (len & 1) B = mul(B, A, y);
    A = mul(A, A, y);
    len >>= 1;
  }
  return B;
}
int main() {
  scanf("%I64d%I64d", &n, &k);
  memset(pre.m, 0, sizeof(pre.m));
  memset(A.m, 0, sizeof(A.m));
  for (long long i = 0; i < 16; i++) {
    for (long long j = i - 1; j < i + 2 && j < 16; j++) {
      if (j >= 0 && j <= 15) {
        A.m[i][j] = 1;
      }
    }
  }
  long long flag = 0;
  pre.m[0][0] = 1;
  for (long long i = 1; i <= n; i++) {
    long long L, R, y;
    scanf("%I64d%I64d%I64d", &L, &R, &y);
    if (R > k) R = k, flag = 1;
    B = quick_pow(A, R - L, y);
    for (long long j = y + 1; j <= 15; j++) pre.m[j][0] = 0;
    B = mul(B, pre, y);
    for (long long j = 0; j <= y; j++) {
      pre.m[j][0] = B.m[j][0];
    }
    if (flag == 1) break;
  }
  printf("%I64d\n", B.m[0][0]);
}
