#include <bits/stdc++.h>
using namespace std;
const int Maxn = 17;
const int Pr = 1e9 + 7;
struct Matrix {
  long long n, m;
  long long mat[Maxn][Maxn];
  Matrix() = default;
  Matrix(long long _n, long long _m) : n(_n), m(_m) {}
  void Clear() { memset(mat, 0, sizeof(mat)); }
  Matrix operator+(const Matrix &M) const {
    Matrix res(n, m);
    for (long long i = 0; i < n; ++i)
      for (long long j = 0; j < m; ++j) {
        res.mat[i][j] = (mat[i][j] + M.mat[i][j]) % Pr;
      }
    return res;
  }
  Matrix operator*(const Matrix &M) const {
    if (m != M.n) return Matrix(-1, -1);
    Matrix res(n, M.m);
    res.Clear();
    for (long long i = 0; i < n; ++i)
      for (long long j = 0; j < M.m; ++j) {
        for (long long k = 0; k < m; ++k) {
          res.mat[i][j] += mat[i][k] * M.mat[k][j];
          res.mat[i][j] %= Pr;
        }
      }
    return res;
  }
  Matrix operator^(long long b) const {
    if (n != m) return Matrix(-1, -1);
    Matrix a(*this);
    Matrix res(n, n);
    res.Clear();
    for (long long i = 0; i < n; ++i) res.mat[i][i] = 1;
    for (; b; b >>= 1) {
      if (b & 1) {
        res = a * res;
      }
      a = a * a;
    }
    return res;
  }
  void Print() {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) cout << mat[i][j] << ' ';
      cout << '\n';
    }
  }
};
long long N, K;
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> K;
  Matrix pwr(Maxn, Maxn);
  pwr.Clear();
  for (int i = 0; i < Maxn; ++i) {
    pwr.mat[i][i] = 1;
    if (i > 0) pwr.mat[i][i - 1] = 1;
    if (i + 1 < Maxn) pwr.mat[i][i + 1] = 1;
  }
  Matrix dp(Maxn, 1);
  dp.Clear();
  dp.mat[0][0] = 1;
  long long a, b, c;
  while (N--) {
    cin >> a >> b >> c;
    ++c;
    if (b > K) b = K;
    for (int i = dp.n; i < Maxn; ++i) dp.mat[i][0] = 0;
    dp.n = c;
    pwr.n = pwr.m = c;
    dp = (pwr ^ (b - a)) * dp;
  }
  cout << dp.mat[0][0];
  return 0;
}
