#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const long double eps = 1e-10;
template <typename T1, typename T2>
inline void chmin(T1& a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1& a, T2 b) {
  if (a < b) a = b;
}
vector<vector<long long>> matmul(vector<vector<long long>>& A,
                                 vector<vector<long long>>& B) {
  int n = A.size();
  int m = B.size();
  int l = B[0].size();
  vector<vector<long long>> ret(n, vector<long long>(l));
  for (int i = (int)(0); i < (int)(n); i++)
    for (int k = (int)(0); k < (int)(l); k++)
      for (int j = (int)(0); j < (int)(m); j++)
        (ret[i][k] += A[i][j] * B[j][k]) %= mod;
  return ret;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  long long k;
  cin >> n >> k;
  vector<long long> A(n), B(n), C(n);
  for (int i = (int)(0); i < (int)(n); i++) cin >> A[i] >> B[i] >> C[i];
  B[n - 1] = k;
  auto coef = [&](long long n, long long c) {
    vector<vector<long long>> M(c + 1, vector<long long>(c + 1));
    for (int i = (int)(0); i < (int)(c + 1); i++)
      for (int di = (int)(0); di < (int)(3); di++) {
        if (i - 1 + di >= 0 && i - 1 + di < c + 1) {
          M[i][i - 1 + di] = 1LL;
        }
      }
    vector<vector<vector<long long>>> MM(
        60, vector<vector<long long>>(c + 1, vector<long long>(c + 1)));
    copy(M.begin(), M.end(), begin(MM[0]));
    for (int i = 1; i < 60; i++) {
      MM[i] = matmul(MM[i - 1], MM[i - 1]);
      for (int j = (int)(0); j < (int)(c + 1); j++)
        for (int k = (int)(0); k < (int)(c + 1); k++)
          (MM[i][j][k] += mod) %= mod;
    }
    vector<vector<long long>> K(c + 1, vector<long long>(c + 1));
    for (int i = (int)(0); i < (int)(c + 1); i++) K[i][i] = 1;
    for (int i = (int)(0); i < (int)(60); i++)
      if (n >> i & 1) {
        K = matmul(K, MM[i]);
        for (int j = (int)(0); j < (int)(c + 1); j++)
          for (int k = (int)(0); k < (int)(c + 1); k++) (K[j][k] += mod) %= mod;
      }
    return K;
  };
  vector<vector<vector<long long>>> dp(
      n + 1, vector<vector<long long>>(16, vector<long long>(1)));
  dp[0][0][0] = 1;
  for (int i = (int)(0); i < (int)(n); i++) {
    auto M = coef(B[i] - A[i], C[i]);
    vector<vector<long long>> a(C[i] + 1, vector<long long>(1));
    for (int j = (int)(0); j < (int)(C[i] + 1); j++) a[j][0] = dp[i][j][0];
    auto ret = matmul(M, a);
    for (int j = (int)(0); j < (int)(C[i] + 1); j++)
      dp[i + 1][j][0] = ret[j][0];
  }
  cout << dp[n][0][0] << '\n';
  return 0;
}
