#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int n;
long long k;
long long a[MAXN], b[MAXN], c[MAXN];
long long MOD = 1000000007;
const int MC = 20;
struct matrix {
  long long l;
  long long e[MC][MC];
  matrix operator*(const matrix &m) const {
    matrix res;
    res.l = l;
    for (int i = 0; i < l; i++) {
      for (int j = 0; j < l; j++) {
        res.e[i][j] = 0;
        for (int k = 0; k < l; k++) {
          res.e[i][j] += e[i][k] * m.e[k][j];
          res.e[i][j] %= MOD;
        }
      }
    }
    return res;
  }
};
matrix bin_pow(matrix m, long long exp) {
  if (exp == 1) return m;
  matrix h = bin_pow(m, exp / 2);
  if (exp % 2 == 0) return h * h;
  return h * h * m;
}
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld%lld", a + i, b + i, c + i);
  }
  b[n - 1] = min(b[n - 1], k);
  if (a[n - 1] == k) n--;
  long long x[MC];
  x[0] = 1;
  for (int j = 1; j < MC; j++) x[j] = 0;
  long long y[MC];
  for (int I = 0; I < n; I++) {
    matrix m;
    m.l = c[I] + 1;
    long long L = b[I] - a[I];
    for (int i = 0; i < m.l; i++)
      for (int j = 0; j < m.l; j++)
        if (abs(i - j) <= 1)
          m.e[i][j] = 1;
        else
          m.e[i][j] = 0;
    m = bin_pow(m, L);
    for (int i = 0; i < MC; i++) y[i] = 0;
    for (int i = 0; i < m.l; i++) {
      y[i] = 0;
      for (int j = 0; j < m.l; j++) {
        y[i] += m.e[i][j] * x[j];
        y[i] %= MOD;
      }
    }
    for (int i = 0; i < MC; i++) x[i] = y[i];
  }
  long long res = x[0];
  printf("%lld\n", res);
  return 0;
}
