#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a < 0) a += mod;
  a %= mod;
}
struct matrix {
  int e[16 + 5][16 + 5], n, m;
  matrix() {}
  matrix(int _n, int _m) : n(_n), m(_m) { memset(e, 0, sizeof(e)); }
  matrix operator*(const matrix &temp) const {
    matrix ret = matrix(n, temp.m);
    for (int i = 1; i <= ret.n; i++) {
      for (int j = 1; j <= ret.m; j++) {
        for (int k = 1; k <= m; k++) {
          add(ret.e[i][j], 1LL * e[i][k] * temp.e[k][j] % mod);
        }
      }
    }
    return ret;
  }
  matrix operator+(const matrix &temp) const {
    matrix ret = matrix(n, m);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        add(ret.e[i][j], (e[i][j] + temp.e[i][j]) % mod);
      }
    }
    return ret;
  }
  void getE() {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        e[i][j] = i == j ? 1 : 0;
      }
    }
  }
};
matrix qpow(matrix temp, long long x) {
  int sz = temp.n;
  matrix base = matrix(sz, sz);
  base.getE();
  while (x) {
    if (x & 1) base = base * temp;
    x >>= 1;
    temp = temp * temp;
  }
  return base;
}
void print(matrix p) {
  int n = p.n;
  int m = p.m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      printf("%d ", p.e[i][j]);
    }
    cout << endl;
  }
}
int main() {
  int n;
  long long k;
  cin >> n >> k;
  matrix ans = matrix(16, 16);
  ans.e[1][1] = 1;
  for (int i = 1; i <= n; i++) {
    long long x, y;
    int h;
    scanf("%I64d%I64d%d", &x, &y, &h);
    if (x >= k) continue;
    h++;
    matrix temp = matrix(h, h);
    for (int i = 1; i <= h; i++) {
      temp.e[i][i] = 1;
      for (int j = -1; j <= 1; j++) {
        if (i + j >= 1) temp.e[i + j][i] = 1;
        if (i + j <= h) temp.e[i + j][i] = 1;
      }
    }
    ans = ans * qpow(temp, min(y, k) - x);
  }
  cout << ans.e[1][1] << endl;
  return 0;
}
