#include <bits/stdc++.h>
using namespace std;
long long n, k, a[111], b[111], c[111], cur[22][22], aux[22][22], ori[22][22],
    tmp[22][22];
void mul(long long in1[22][22], long long in2[22][22], long long out[22][22]) {
  for (int i = (0); i <= ((int)(18) - 1); i++)
    for (int j = (0); j <= ((int)(18) - 1); j++) {
      aux[i][j] = 0;
      for (int k = (0); k <= ((int)(18) - 1); k++)
        aux[i][j] += in1[i][k] * in2[k][j], aux[i][j] %= 1000000007;
    }
  for (int i = (0); i <= ((int)(18) - 1); i++)
    for (int j = (0); j <= ((int)(18) - 1); j++) out[i][j] = aux[i][j];
}
void expo(long long x) {
  memset(tmp, 0, sizeof(tmp));
  for (int i = (0); i <= ((int)(18) - 1); i++) tmp[i][i] = 1;
  for (int i = (62); i >= (0); i--) {
    mul(tmp, tmp, tmp);
    if ((1LL << i) & x) mul(tmp, ori, tmp);
  }
}
void construct(int y) {
  memset(ori, 0, sizeof(ori));
  ori[0][0] = ori[1][0] = 1;
  for (int j = (1); j <= (y); j++)
    ori[j][j] = ori[j - 1][j] = ori[j + 1][j] = 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = (0); i <= ((int)(n)-1); i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  b[n - 1] = min(b[n - 1], k);
  for (int i = (0); i <= ((int)(18) - 1); i++) cur[i][i] = 1;
  for (int i = (0); i <= ((int)(n)-1); i++) {
    memset(tmp, 0, sizeof(tmp));
    for (int j = (0); j <= (c[i]); j++) tmp[j][j] = 1;
    mul(cur, tmp, cur);
    construct(c[i]);
    if (b[i] > a[i]) {
      expo(b[i] - a[i]);
      mul(cur, tmp, cur);
    }
  }
  cout << cur[0][0];
}
