#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int p = 1e9 + 7;
long long a[maxn], b[maxn], c[maxn], k, t;
int sz = 15;
struct mat {
  long long m[25][25];
  void init() { memset(m, 0, sizeof m); }
  void one() {
    init();
    for (int i = 0; i <= sz; ++i) m[i][i] = 1;
  }
} tmp, res;
mat mul(mat a, mat b) {
  mat c;
  for (int i = 0; i <= sz; ++i)
    for (int j = 0; j <= sz; ++j) {
      c.m[i][j] = 0;
      for (int k = 0; k <= sz; ++k)
        c.m[i][j] = (c.m[i][j] + a.m[i][k] * b.m[k][j]) % p;
    }
  return c;
}
void pow_mod(long long n) {
  while (n) {
    if (n & 1) res = mul(res, tmp);
    tmp = mul(tmp, tmp);
    n >>= 1;
  }
}
int main() {
  cin >> t >> k;
  for (int i = 1; i <= t; ++i) scanf("%lld%lld%lld", a + i, b + i, c + i);
  res.one();
  for (int i = 1; i <= t; ++i) {
    tmp.init();
    for (int j = 0; j <= c[i]; ++j) {
      if (j + 1 <= c[i]) ++tmp.m[j][j + 1];
      if (j - 1 >= 0) ++tmp.m[j][j - 1];
      ++tmp.m[j][j];
    }
    b[i] >= k ? pow_mod(k - a[i]) : pow_mod(b[i] - a[i]);
  }
  printf("%lld\n", res.m[0][0]);
  return 0;
}
