#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int maxn = 10007;
const int inf = 1000000000;
long long n, k, h;
long long t[20][20], x[20][20], temp[20][20];
long long ans[20], tans[20];
void mul(long long a[20][20], long long b[20][20], int m) {
  for (int i = 0; i <= m; ++i)
    for (int j = 0; j <= m; ++j) temp[i][j] = 0;
  for (int i = 0; i <= m; ++i)
    for (int j = 0; j <= m; ++j)
      for (int l = 0; l <= m; ++l)
        temp[i][j] = (temp[i][j] + a[i][l] * b[l][j]) % mod;
  for (int i = 0; i <= m; ++i)
    for (int j = 0; j <= m; ++j) a[i][j] = temp[i][j];
}
void calc(int m, long long p) {
  for (int i = 0; i <= m; ++i)
    for (int j = 0; j <= m; ++j) t[i][j] = i == j ? 1 : 0;
  for (int i = 0; i <= m; ++i)
    for (int j = 0; j <= m; ++j)
      x[i][j] = (i == j || i + 1 == j || i - 1 == j ? 1 : 0);
  while (p) {
    if (p & 1) {
      mul(t, x, m);
    }
    mul(x, x, m);
    p /= 2;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  ans[0] = 1;
  for (int i = 0; i < n; ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    h = min(c, h);
    calc(c, min(b, k) - a);
    for (int i = h + 1; i <= c; ++i) ans[i] = 0;
    for (int i = 0; i <= c; ++i) {
      tans[i] = 0;
      for (int j = 0; j <= c; ++j) tans[i] = (tans[i] + ans[j] * t[j][i]) % mod;
    }
    h = c;
    for (int i = 0; i <= c; ++i) ans[i] = tans[i];
  }
  cout << ans[0] << endl;
  return 0;
}
