#include <bits/stdc++.h>
using namespace std;
class Int {
 private:
  static const int MOD = 1e9 + 7;
  int x;

 public:
  Int(int _x = 0) : x(_x) {
    x %= MOD;
    if (x < 0) x += MOD;
  }
  Int(const Int &p) { x = p.x; }
  Int operator+(Int p) {
    Int tmp(x + p.x);
    return Int(x + p.x);
  }
  Int operator*(Int p) { return Int(x * 1ll * p.x % MOD); }
  void operator+=(Int p) { *this = *this + p; }
  friend ostream &operator<<(ostream &out, Int p) {
    out << p.x;
    return out;
  }
};
class Matrix {
 private:
  vector<vector<Int>> a;

 public:
  Matrix(int n = 0, int m = 0) { a.resize(n, vector<Int>(m, Int(0))); }
  ~Matrix() {}
  static Matrix Identity(int n) {
    Matrix res(n, n);
    for (int i = 0; i < n; ++i) {
      res[i][i] = 1;
    }
    return res;
  }
  int rows_amount() const { return a.size(); }
  int columns_amount() const { return a.empty() ? 0u : a[0].size(); }
  vector<Int> &operator[](size_t i) { return a[i]; }
  Matrix transpose() {
    Matrix res(this->columns_amount(), this->rows_amount());
    for (int i = 0; i < rows_amount(); ++i) {
      for (int j = 0; j < columns_amount(); ++j) {
        res[j][i] = a[i][j];
      }
    }
    return res;
  }
  Matrix operator*(Matrix b) {
    if (columns_amount() != b.rows_amount()) {
      return Matrix();
    }
    Matrix res(rows_amount(), b.columns_amount());
    int n = rows_amount();
    int m = columns_amount();
    int l = b.columns_amount();
    b = b.transpose();
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        res[i][j] =
            inner_product(a[i].begin(), a[i].end(), b[j].begin(), res[i][j]);
      }
    }
    return res;
  }
  void operator*=(Matrix p) { *this = *this * p; }
  Matrix operator^(long long n) {
    if (rows_amount() != columns_amount()) return Matrix();
    Matrix res = Identity(16);
    Matrix x = *this;
    while (n > 0) {
      if (n & 1) res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  friend ostream &operator<<(ostream &out, Matrix p) {
    int n = p.rows_amount();
    int m = p.columns_amount();
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        out << p[i][j] << ' ';
      }
      out << '\n';
    }
    return out;
  }
};
int n;
long long k;
vector<long long> a, b;
vector<int> c;
void load() {
  cin >> n >> k;
  a.resize(n);
  b.resize(n);
  c.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i] >> c[i];
  }
  b[n - 1] = k;
}
Matrix build_matrix(int n) {
  Matrix res(16, 16);
  for (int i = 0; i <= n; ++i) {
    for (int j = -1; j <= 1; ++j) {
      if (i + j > -1 && i + j <= n) {
        res[i][i + j] = 1;
      }
    }
  }
  return res;
}
void solve() {
  Matrix vec(1, 16);
  vec[0][0] = 1;
  Matrix m = Matrix::Identity(16);
  for (int i = 0; i < n; ++i) {
    Matrix p = build_matrix(c[i]);
    m *= p ^ (b[i] - a[i]);
  }
  Matrix ans = vec * m;
  cout << ans[0][0] << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  load();
  solve();
  return 0;
}
