#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VL = vector<LL>;
using VVL = vector<VL>;
const int INF = 1e9;
const LL LINF = 1e16;
const LL MOD = 1000000007;
const double PI = acos(-1.0);
int DX[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int DY[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int s = 0;
vector<vector<LL> > mul(const vector<vector<LL> >& A,
                        const vector<vector<LL> >& B) {
  const int R = A.size(), C = B[0].size(), sz = B.size();
  vector<vector<LL> > AB(R, vector<LL>(C));
  for (int i = 0; i < R; ++i)
    for (int j = 0; j < C; ++j)
      for (int k = 0; k < sz; ++k) (AB[i][j] += A[i][k] * B[k][j] % MOD) %= MOD;
  return AB;
}
vector<vector<LL> > powA(const vector<vector<LL> >& A, LL n) {
  const int N = A.size();
  vector<vector<LL> > p(N, vector<LL>(N, 0)), w = A;
  for (int i = 0; i < N; ++i) p[i][i] = 1;
  while (n > 0) {
    if (n & 1) p = mul(p, w);
    w = mul(w, w);
    n >>= 1;
  }
  return p;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  LL N, K;
  cin >> N >> K;
  vector<vector<LL> > crt(16, vector<LL>(1));
  crt[0][0] = 1;
  for (int(i) = (0); (i) < (N); (i)++) {
    LL a, b, c;
    cin >> a >> b >> c;
    if (K < b) b = K;
    VVL tmp(c + 1, vector<LL>(c + 1));
    for (int(i) = (0); (i) < (c + 1); (i)++) {
      if (i - 1 >= 0) tmp[i][i - 1] = 1;
      tmp[i][i] = 1;
      if (i + 1 < c + 1) tmp[i][i + 1] = 1;
    }
    tmp = powA(tmp, b - a);
    VVL y(c + 1, vector<LL>(1));
    for (int(i) = (0); (i) < (min(c + 1, (LL) int((crt).size()))); (i)++)
      y[i][0] = crt[i][0];
    crt = mul(tmp, y);
  }
  cout << crt[0][0] << endl;
  return 0;
}
