#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int maxn = 110;
void read(long long& x) {
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
}
long long a[maxn], b[maxn], c[maxn];
long long n;
long long k;
struct Matrix {
  long long a[20][20];
  void clear() { memset(a, 0, sizeof(a)); }
  Matrix(int tp = 0) {
    memset(a, 0, sizeof(a));
    if (tp == 1) {
      for (int i = 0; i <= 16; i++) a[i][i] = 1;
    } else if (tp == 2) {
      a[0][0] = 1;
    }
  }
  Matrix operator*(const Matrix& A) const {
    Matrix ret;
    for (int k = 0; k <= 15; k++)
      for (int i = 0; i <= 15; i++)
        for (int j = 0; j <= 15; j++)
          ret.a[i][j] = (ret.a[i][j] + a[i][k] * A.a[k][j] % mod) % mod;
    return ret;
  }
  Matrix operator^(long long y) const {
    Matrix ret(1);
    Matrix x = *this;
    while (y) {
      if (y & 1LL) ret = ret * x;
      x = x * x;
      y >>= 1;
    }
    return ret;
  }
} Ans;
int main() {
  read(n);
  read(k);
  for (int i = 1; i <= n; i++) read(a[i]), read(b[i]), read(c[i]);
  for (int i = 1; i <= n; i++)
    if (b[i] >= k) {
      b[i] = k;
      n = i;
    }
  Ans.a[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    Matrix t;
    for (int j = 0; j <= c[i]; j++) {
      if (j != 0) t.a[j][j - 1] = 1;
      t.a[j][j] = 1;
      if (j != c[i]) t.a[j][j + 1] = 1;
    }
    Ans = (t ^ (b[i] - a[i])) * Ans;
  }
  cout << Ans.a[0][0];
  return 0;
}
