#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void rt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    rt(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
const int maxn = 20, p = 1000000007;
int N;
struct mat {
  int v[maxn][maxn];
} ret, a, tmp;
void upd(int &x, long long y) { x = (x + y) % p; }
mat operator*(const mat &a, const mat &b) {
  memset(tmp.v, 0, sizeof tmp.v);
  for (int i = int(0); i <= (int)(N - 1); i++)
    for (int j = int(0); j <= (int)(N - 1); j++) {
      for (int k = int(0); k <= (int)(N - 1); k++)
        upd(tmp.v[i][j], (long long)a.v[i][k] * b.v[k][j]);
    }
  return tmp;
}
void qpow(long long b) {
  memset(ret.v, 0, sizeof ret.v);
  for (int i = int(0); i <= (int)(N - 1); i++) ret.v[i][i] = 1;
  for (; b; b >>= 1, a = a * a)
    if (b & 1) ret = ret * a;
}
struct vec {
  int v[maxn];
} ans, tmv;
vec operator*(const vec &a, const mat &b) {
  memset(tmv.v, 0, sizeof tmv.v);
  for (int i = int(0); i <= (int)(N - 1); i++)
    for (int j = int(0); j <= (int)(N - 1); j++)
      upd(tmv.v[j], (long long)a.v[i] * b.v[i][j]);
  return tmv;
}
int n;
long long k;
int main() {
  n = rd(), k = rd();
  ans.v[0] = 1;
  for (int i = int(1); i <= (int)(n); i++) {
    long long l = rd(), r = rd();
    N = rd() + 1;
    memset(a.v, 0, sizeof a.v);
    for (int i = int(0); i <= (int)(N - 1); i++)
      for (int j = int(-1); j <= (int)(1); j++)
        if (i + j >= 0 && i + j < N) a.v[i][i + j] = 1;
    qpow(min(r, k) - l);
    ans = ans * ret;
  }
  rt(ans.v[0]);
}
