#include <bits/stdc++.h>
using namespace std;
struct Matrix {
  long long a[20][20];
  Matrix() { memset(a, 0, sizeof(a)); }
  void print() {
    for (int i = 0; i < 16; i++) {
      for (int j = 0; j < 16; j++) {
        printf("%lld ", a[i][j]);
      }
      printf("\n");
    }
    printf("\n");
  }
} A[110];
int n;
long long k;
long long a[110], b[110];
int c[110];
Matrix mul(Matrix A, Matrix B) {
  Matrix C;
  for (int k = 0; k < 16; k++) {
    for (int i = 0; i < 16; i++) {
      for (int j = 0; j < 16; j++) {
        {
          C.a[i][j] = (C.a[i][j] + (A.a[i][k] * B.a[k][j] % 1000000007ll));
          if (C.a[i][j] > 1000000007ll) C.a[i][j] -= 1000000007ll;
        };
      }
    }
  }
  return C;
}
Matrix ksm(Matrix A, long long b) {
  Matrix ret;
  for (int i = 0; i < 16; i++) ret.a[i][i] = 1;
  while (b) {
    if (b & 1) ret = mul(ret, A);
    A = mul(A, A);
    b >>= 1;
  }
  return ret;
}
Matrix getmat(long long a, long long b, int c) {
  Matrix A;
  for (int i = 0; i <= c; i++) {
    if (i) A.a[i][i - 1]++;
    A.a[i][i]++;
    if (i != c) A.a[i][i + 1]++;
  }
  A = ksm(A, b - a);
  return A;
}
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld%d", &a[i], &b[i], &c[i]);
    b[i] = min(b[i], k);
  }
  for (int i = 1; i <= n; i++) {
    if (b[i] >= a[i]) {
      A[i] = getmat(a[i], b[i], c[i]);
    }
  }
  for (int i = 2; i <= n; i++) A[i] = mul(A[i - 1], A[i]);
  printf("%lld\n", A[n].a[0][0]);
  return 0;
}
