#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& v) {
  os << "(" << v.first << " " << v.second << ")";
  return os;
}
template <typename T, typename U = typename T::value_type,
          typename = typename enable_if<!is_same<T, string>::value>::type>
ostream& operator<<(ostream& os, const T& v) {
  os << '[';
  for (const auto& it : v) os << it << " ";
  if (!v.empty()) os << "\b";
  os << "]";
  return os;
}
const int kM = 16;
const int kMod = 1000000007;
vector<vector<int>> operator*(const vector<vector<int>>& a,
                              const vector<vector<int>>& b) {
  int R1 = a.size();
  int C1 = a[0].size();
  int R2 = b.size();
  int C2 = b[0].size();
  assert(C1 == R2);
  vector<vector<int>> res(R1, vector<int>(C2, 0));
  for (int r = 0; r < (R1); r++)
    for (int c = 0; c < (C2); c++) {
      uint64_t acc = 0;
      for (int i = 0; i < (C1); i++) acc += uint64_t(a[r][i]) * b[i][c];
      res[r][c] = acc % kMod;
    }
  return res;
}
vector<vector<int>> matr_exp(const vector<vector<int>>& matr, int64_t exp) {
  if (exp == 0) {
    int N = matr.size();
    vector<vector<int>> res(N, vector<int>(N));
    for (int i = 0; i < (N); i++) res[i][i] = 1;
    return res;
  }
  if (exp == 1) {
    return matr;
  }
  auto res = matr_exp(matr, exp / 2);
  res = res * res;
  if (exp % 2 == 1) res = res * matr;
  return res;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int N;
  int64_t K;
  cin >> N >> K;
  vector<vector<int>> cnt(1, vector<int>(kM, 0));
  cnt[0][0] = 1;
  for (int i = 0; i < (N); i++) {
    int64_t a, b, c;
    cin >> a >> b >> c;
    if (b > K) b = K;
    for (int i = c + 1; i < kM; i++) cnt[0][i] = 0;
    vector<vector<int>> trans(kM, vector<int>(kM, 0));
    for (int y = 0; y <= c; y++) {
      for (int y1 = y - 1; y1 <= y + 1; y1++) {
        if (y1 < kM && y1 >= 0) trans[y1][y] = 1;
      }
    }
    trans = matr_exp(trans, b - a);
    cnt = cnt * trans;
  }
  cout << cnt[0][0] << endl;
  return 0;
}
