#include <bits/stdc++.h>
using namespace std;
const long long inf = 2 * 1e9;
const int mod = 1e9 + 7;
const int maxn = 102;
int n;
long long k;
pair<long long, int> arr[maxn];
struct matrix {
  int n, m;
  int *mas;
  int **matr;
  matrix(){};
  matrix(int _n, int _m) {
    n = _n;
    m = _m;
    mas = (int *)calloc(4 * n * m, sizeof(int));
    matr = (int **)malloc(4 * n * sizeof(int *));
    for (int i = 0; i < n; ++i) matr[i] = mas + m * i;
  }
  matrix operator*(matrix a) {
    matrix ans = matrix(n, a.m);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < a.m; ++j) {
        ans.matr[i][j] = 0;
        for (int k = 0; k < m; ++k)
          ans.matr[i][j] =
              (ans.matr[i][j] + 1LL * matr[i][k] * a.matr[k][j]) % mod;
      }
    }
    return ans;
  }
  void geti() {
    for (int i = 0; i < n; ++i) {
      matr[i][i] = 1;
      for (int j = i + 1; j < m; ++j) matr[i][j] = matr[j][i] = 0;
    }
  }
  void print() {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) cout << matr[i][j] << " ";
      cout << endl;
    }
    cout << endl;
  }
};
matrix mexp(matrix a, long long pow) {
  if (pow == 0) {
    a.geti();
    return a;
  }
  if (pow == 1) return a;
  matrix b = mexp(a, pow / 2);
  if (pow % 2 == 0)
    return b * b;
  else
    return b * b * a;
}
matrix get_matrix(int h) {
  matrix ans = matrix(16, 16);
  for (int hh = 0; hh <= h; ++hh) {
    for (int i = max(0, hh - 1); i <= min(h, hh + 1); ++i) ans.matr[hh][i] = 1;
  }
  return ans;
}
matrix h = matrix(16, 1);
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i].first >> arr[i + 1].first >> arr[i].second;
  }
  h.matr[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    h = mexp(get_matrix(arr[i].second),
             min(arr[i + 1].first, k) - min(arr[i].first, k)) *
        h;
  }
  cout << h.matr[0][0];
  return 0;
}
