#include <bits/stdc++.h>
using namespace std;
char CRTBUFF[300000];
struct debugger {
  static void call(const char* it) {}
  template <typename T, typename... aT>
  static void call(const char* it, T a, aT... rest) {
    string b;
    for (; *it && *it != ','; ++it)
      if (*it != ' ') b += *it;
    cerr << b << "=" << a << " ";
    call(++it, rest...);
  }
};
struct Matrix {
  vector<long long> vec;
  int R, C;
  inline Matrix() {}
  inline Matrix(int RR, int CC) {
    R = RR, C = CC;
    vec.resize(R * C + 1);
    fill(vec.begin(), vec.end(), 0);
  }
  inline long long* operator[](int x) { return &vec[x * C]; }
  inline Matrix operator*(Matrix& B) {
    Matrix& A = *this;
    Matrix C(A.R, B.C);
    for (int i = 0; i < C.R; i++) {
      for (int j = 0; j < C.C; j++) {
        for (int k = 0; k < A.C; k++) {
          C[i][j] += (1000000007 + A[i][k] * B[k][j]) % 1000000007;
          if (C[i][j] >= 1000000007) C[i][j] -= 1000000007;
        }
      }
    }
    return C;
  }
  inline static Matrix Identity(int R, int C) {
    Matrix M(R, C);
    for (int i = 0; i < min(R, C); i++) M[i][i] = 1;
    return M;
  }
  inline Matrix expo(long long e) {
    Matrix M = *this;
    Matrix ret = Matrix::Identity(R, C);
    while (e) {
      if (e & 1) ret = ret * M;
      M = M * M, e >>= 1;
    }
    return ret;
  }
};
void print(Matrix m) {
  cout << "mat: "
       << "\n";
  for (int i = (0); i < (m.R); i += (1)) {
    for (int j = (0); j < (m.C); j += (1)) cout << m[i][j] << " ";
    cout << "\n";
  }
}
const int lim = 16;
long long A[300010 + 10], B[300010 + 10], C[300010 + 10];
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  };
  long long n, k;
  while (cin >> n >> k) {
    for (int i = (0); i < (n); i += (1)) cin >> A[i] >> B[i] >> C[i];
    Matrix colm(lim, 1), pre(lim, lim);
    colm[0][0] = 1;
    for (int i = (0); i < (lim); i += (1))
      for (int j = ((i - 1)); j < ((i + 1) + 1); j += (1)) {
        if (0 <= j && j < lim) pre[i][j] = 1;
      }
    long long pos = 0;
    for (int i = (0); i < (n); i += (1)) {
      if (pos >= k) break;
      long long nextpos = min(k, B[i]);
      Matrix base = pre;
      for (int x = (0); x < (lim); x += (1))
        for (int y = (0); y < (lim); y += (1)) {
          if (x > C[i] || y > C[i]) base[x][y] = 0;
        }
      colm = base.expo(nextpos - pos) * colm;
      pos = nextpos;
    }
    long long ans = colm[0][0];
    cout << ans << "\n";
  }
}
