#include <bits/stdc++.h>
using namespace std;
const long long HAHA = 1000000007;
long long k, a, b;
int n, c;
vector<long long> xxx = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
vector<long long> ans, tampung;
vector<vector<long long> > identity;
vector<vector<long long> > mul(vector<vector<long long> > a,
                               vector<vector<long long> > b) {
  vector<vector<long long> > d(16, vector<long long>(16));
  for (int i = 0; i < 16; ++i) {
    for (int j = 0; j < 16; ++j) {
      for (int k = 0; k < 16; ++k) {
        d[i][j] = (d[i][j] + a[i][k] * b[k][j]) % HAHA;
      }
    }
  }
  return d;
}
vector<vector<long long> > fast_expo(vector<vector<long long> > a,
                                     long long b) {
  if (b == 0) return identity;
  if (b == 1) return a;
  if (b % 2 == 1) return mul(a, fast_expo(a, b - 1));
  vector<vector<long long> > c = fast_expo(a, b / 2);
  return mul(c, c);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  vector<long long> va;
  for (int i = 0; i < 16; ++i) {
    for (int j = 0; j < 16; ++j) {
      if (i == j)
        va.push_back(1);
      else
        va.push_back(0);
    }
    identity.push_back(va);
  }
  for (int i = 0; i < 16; ++i) {
    tampung.push_back(0);
  }
  ans.push_back(1);
  for (int i = 1; i < 16; ++i) {
    ans.push_back(0);
  }
  vector<vector<long long> > lol;
  cin >> n >> k;
  while (n--) {
    cin >> a >> b >> c;
    if (n == 0) b = k;
    for (int j = c + 1; j < 16; ++j) ans[j] = 0;
    for (int l = 0; l < 16; ++l) lol.push_back(xxx);
    for (int j = 0; j <= c; ++j) {
      lol[j][j] = 1;
      if (j >= 1) lol[j][j - 1] = 1;
      if (j < c) lol[j][j + 1] = 1;
    }
    lol = fast_expo(lol, b - a);
    for (int j = 0; j < 16; ++j) {
      for (int r = 0; r < 16; ++r) {
        tampung[j] = (tampung[j] + lol[j][r] * ans[r]) % HAHA;
      }
    }
    for (int j = 0; j < 16; ++j) ans[j] = tampung[j];
    for (int j = 0; j < 16; ++j) tampung[j] = 0;
    lol.clear();
  }
  cout << ans[0] % HAHA;
}
