#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
void init(vector<vector<int>>& m) { m.resize(16, vector<int>(16, 0)); }
vector<vector<int>> mult(vector<vector<int>> a, vector<vector<int>> b) {
  vector<vector<int>> res;
  init(res);
  for (int i = 0; i <= 15; i++)
    for (int j = 0; j <= 15; j++)
      for (int k = 0; k <= 15; k++)
        res[i][j] = (res[i][j] + (long long)a[i][k] * b[k][j] % Mod) % Mod;
  return res;
}
vector<vector<int>> U;
vector<vector<int>> fp(vector<vector<int>>& x, long long p) {
  if (!p) return U;
  vector<vector<int>> y = fp(x, p >> 1);
  y = mult(y, y);
  if (p & 1) y = mult(y, x);
  return y;
}
int main() {
  init(U);
  for (int i = 0; i <= 15; i++) U[i][i] = 1;
  long long n, k;
  cin >> n >> k;
  vector<vector<int>> B;
  init(B);
  B[0][0] = 1;
  while (n--) {
    long long a, b, c;
    cin >> a >> b >> c;
    b = min(b, k);
    vector<vector<int>> T;
    init(T);
    for (int i = c + 1; i <= 15; i++) B[0][i] = 0;
    for (int i = 0; i <= c; i++)
      for (int j = 0; j <= c; j++) T[i][j] = (abs(i - j) <= 1);
    T = fp(T, b - a);
    B = mult(B, T);
  }
  cout << B[0][0] << endl;
  return 0;
}
