#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "[";
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (it != a.begin()) out << ", ";
    out << *it;
  }
  return out << "]";
}
const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = 1e9 + 7;
const long double PI = acosl(-1.0);
const long double EPS = 1e-9;
mt19937 rnd(time(NULL));
mt19937_64 rnd64(time(NULL));
const int N = 100 + 13;
int n;
long long k;
pair<pair<long long, long long>, int> a[N];
bool read() {
  if (!(cin >> n >> k)) return false;
  for (int i = 0; i < int(n); ++i)
    cin >> a[i].first.first >> a[i].first.second >> a[i].second;
  return true;
}
int add(int first, int second) {
  first += second;
  if (first < 0) first += MOD;
  if (first >= MOD) first -= MOD;
  return first;
}
int mul(int first, int second) { return first * 1ll * second % MOD; }
vector<vector<int>> mul(vector<vector<int>> a, vector<vector<int>> b) {
  int n = int((a).size());
  vector<vector<int>> c(n, vector<int>(n, 0));
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(n); ++j)
      for (int k = 0; k < int(n); ++k)
        c[i][j] = add(c[i][j], mul(a[i][k], b[k][j]));
  return c;
}
vector<vector<int>> binpow(vector<vector<int>> a, long long b) {
  int n = int((a).size());
  vector<vector<int>> res(n, vector<int>(n, 0));
  for (int i = 0; i < int(n); ++i) res[i][i] = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
int dp[N][N];
void solve() {
  a[n - 1].first.second = k;
  a[n++] = make_pair(make_pair(k, k), 0);
  dp[0][0] = 1;
  for (int i = 0; i < int(n - 1); ++i) {
    int t = a[i].second + 1;
    vector<vector<int>> first(t, vector<int>(t, 0));
    for (int j = 0; j < int(t); ++j) {
      if (j > 0) first[j][j - 1] = 1;
      first[j][j] = 1;
      if (j + 1 < t) first[j][j + 1] = 1;
    }
    first = binpow(first, a[i].first.second - a[i].first.first);
    int nt = min(t, a[i + 1].second + 1);
    for (int j = 0; j < int(nt); ++j)
      for (int jj = 0; jj < int(t); ++jj)
        dp[i + 1][j] = add(dp[i + 1][j], mul(first[j][jj], dp[i][jj]));
  }
  cout << dp[n - 1][0] << endl;
}
int main() {
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  if (read()) {
    solve();
  }
}
