#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long oo = 1LL << 50;
struct matrix {
  long long m[25][25], n;
  matrix() {}
  matrix(long long n, long long p) : n(n) {
    memset(m, 0, sizeof(m));
    for (long long i = 1; i <= n; i++) m[i][i] = p;
  }
};
matrix operator*(matrix a, matrix b) {
  matrix c = matrix(a.n, 0);
  for (long long k = 1; k <= a.n; k++)
    for (long long i = 1; i <= a.n; i++)
      for (long long j = 1; j <= a.n; j++)
        (c.m[i][j] += a.m[i][k] * b.m[k][j] % mod) %= mod;
  return c;
}
long long N, K;
matrix A, B;
namespace solution {
void Solve() {
  scanf("%lld%lld", &N, &K);
  A = matrix(16, 0);
  A.m[1][1] = 1;
  for (long long o = 1; o <= N; o++) {
    B = matrix(16, 0);
    long long l, r, c;
    scanf("%lld%lld%lld", &l, &r, &c);
    c++;
    r = min(r, K);
    for (long long i = 1; i <= c; i++)
      for (long long j = i - 1; j <= i + 1; j++)
        if (j >= 1 && j <= c) B.m[j][i]++;
    long long len = r - l;
    while (len) {
      if (len & 1) A = A * B;
      B = B * B;
      len >>= 1;
    }
  }
  printf("%lld\n", A.m[1][1]);
}
}  // namespace solution
int main() {
  using namespace solution;
  Solve();
  return 0;
}
