#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Mod {
  static const int P = int(1e9 + 7);
  ll k;
  Mod() = default;
  Mod(const ll k) : k(k % P) {}
};
Mod operator+(const Mod a, const Mod b) { return a.k + b.k; }
Mod operator*(const Mod a, const Mod b) { return a.k * b.k; }
Mod& operator+=(Mod& a, const Mod b) { return a = a + b; }
const int max_height = 16;
using matrix = array<array<Mod, max_height>, max_height>;
matrix operator*(const matrix& a, const matrix& b) {
  matrix c{};
  for (int i = 0; i < max_height; i++)
    for (int k = 0; k < max_height; k++)
      for (int j = 0; j < max_height; j++) c[i][k] += a[i][j] * b[j][k];
  return c;
}
matrix& operator*=(matrix& a, const matrix& b) { return a = a * b; }
matrix f(const int height, const ll width) {
  matrix one_step;
  for (int i = 0; i < max_height; i++)
    for (int j = 0; j < max_height; j++)
      one_step[i][j] = i <= height && j <= height && abs(i - j) <= 1;
  if (width == 1)
    return one_step;
  else {
    matrix a = f(height, width / 2);
    a = a * a;
    if (width % 2 == 1) a = a * one_step;
    return a;
  }
}
int main() {
  int n;
  ll k;
  cin >> n >> k;
  matrix ways{};
  for (int i = 0; i < max_height; i++) ways[i][i] = 1;
  for (int i = 0; i < n; i++) {
    ll a, b;
    int c;
    cin >> a >> b >> c;
    if (i == n - 1) b = k;
    if (a != b) ways *= f(c, b - a);
  }
  cout << ways[0][0].k << endl;
}
