#include <bits/stdc++.h>
using namespace std;
const int maxn = 20;
struct matrax {
  long long int a[maxn][maxn];
};
matrax A, e;
const long long mod = 1e9 + 7;
void init() {
  memset(e.a, 0, sizeof(e.a));
  for (int i = 0; i < maxn; i++) e.a[i][i] = 1;
}
matrax mult(matrax a, matrax b) {
  matrax c;
  memset(c.a, 0, sizeof(c.a));
  for (int i = 0; i < maxn; i++) {
    for (int k = 0; k < maxn; k++) {
      if (a.a[i][k]) {
        for (int j = 0; j < maxn; j++) {
          c.a[i][j] = (c.a[i][j] + a.a[i][k] * b.a[k][j]) % mod;
          c.a[i][j] = (c.a[i][j] + mod) % mod;
        }
      }
    }
  }
  return c;
}
matrax power(matrax A, long long int k) {
  matrax ans = e;
  while (k) {
    if (k & 1) ans = mult(ans, A);
    k >>= 1;
    A = mult(A, A);
  }
  return ans;
}
void show(matrax A, int tot) {
  for (int i = 0; i < tot; i++) {
    for (int j = 0; j < tot; j++) {
      cout << A.a[i][j] << " ";
    }
    cout << endl;
  }
}
int n;
long long int k;
long long int a, b, c;
int hang = 1;
int lie = 16;
long long int x[maxn];
long long int temp[maxn];
int main() {
  cin >> n >> k;
  init();
  memset(A.a, 0, sizeof(A.a));
  x[0] = 1;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    c++;
    b = min(b, k);
    memset(A.a, 0, sizeof(A.a));
    for (int i = 0; i < c; i++) A.a[i][i] = 1;
    for (int i = 0; i < c; i++) {
      for (int j = i - 1; j <= i + 1; j++) {
        if (j >= 0 && j < c) {
          A.a[i][j] = 1;
        }
      }
    }
    matrax ans = power(A, b - a);
    memset(temp, 0, sizeof(temp));
    for (int i = 0; i < c; i++) {
      for (int j = 0; j < c; j++) {
        temp[i] = (temp[i] + ans.a[i][j] * x[j]) % mod;
        temp[i] = (temp[i] + mod) % mod;
      }
    }
    memset(x, 0, sizeof(x));
    for (int i = 0; i < c; i++) x[i] = temp[i];
  }
  cout << x[0] << endl;
  return 0;
}
