#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 2e5 + 5;
void multiply(vector<vector<long long>> &a, vector<vector<long long>> &b) {
  int n = a.size();
  vector<vector<long long>> mul(n, vector<long long>(n, 0));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++)
        mul[i][j] = (mul[i][j] + a[i][k] * b[k][j]) % mod;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) a[i][j] = mul[i][j];
}
vector<vector<long long>> power(vector<vector<long long>> M,
                                unsigned long long y) {
  int n = M.size();
  vector<vector<long long>> F(n, vector<long long>(n, 0));
  for (int i = 0; i < n; i++) F[i][i] = 1;
  while (y) {
    if (y & 1) multiply(F, M);
    y >>= 1;
    multiply(M, M);
  }
  return F;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  long long m = 16;
  vector<vector<long long>> F(m, vector<long long>(m, 0));
  long long i, j, k;
  for (i = 0; i < m; i++) F[i][i] = 1;
  long long n, last;
  cin >> n >> last;
  for (i = 0; i < n; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    vector<vector<long long>> M(m, vector<long long>(m, 0));
    for (j = 0; j <= z; j++) {
      M[j][j] = 1;
      if (j != 0) M[j][j - 1] = 1;
      if (j != z) M[j][j + 1] = 1;
    }
    y = min(y, last);
    vector<vector<long long>> pw = power(M, y - x);
    multiply(F, pw);
  }
  cout << F[0][0];
  return 0;
}
