#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 2e5 + 5;
struct Matrix {
  long long mat[20][20];
  void clear() { memset(mat, 0, sizeof(mat)); }
};
Matrix mut(Matrix p, Matrix q, int len) {
  Matrix ans;
  ans.clear();
  for (int i = 0; i <= len; i++)
    for (int j = 0; j <= len; j++)
      for (int k = 0; k <= len; k++)
        ans.mat[i][j] = (ans.mat[i][j] + p.mat[i][k] * q.mat[k][j] % mod) % mod;
  return ans;
}
long long dp[16];
Matrix Pow(long long k, int len) {
  Matrix ans, p;
  ans.clear();
  p.clear();
  for (int i = 0; i <= len; i++) ans.mat[i][i] = 1;
  for (int i = 0; i <= len; i++)
    p.mat[i][(i > 0 ? i - 1 : i)] = p.mat[i][i] =
        p.mat[i][i < len ? i + 1 : i] = 1;
  while (k) {
    if (k & 1) ans = mut(ans, p, len);
    p = mut(p, p, len);
    k >>= 1;
  }
  return ans;
}
void change(Matrix p, int len) {
  Matrix q;
  q.clear();
  for (int i = 0; i <= len; i++) q.mat[i][0] = dp[i];
  q = mut(p, q, len);
  for (int i = 0; i <= len; i++) {
    dp[i] = q.mat[i][0];
  }
}
int main() {
  int n;
  long long k;
  scanf("%d%lld", &n, &k);
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    long long l, r;
    int c;
    scanf("%lld%lld%d", &l, &r, &c);
    if (r > k) r = k;
    Matrix p = Pow(r - l, c);
    for (int i = c + 1; i < 16; i++) dp[i] = 0;
    change(p, c);
  }
  printf("%lld\n", dp[0] % mod);
  return 0;
}
