#include <bits/stdc++.h>
using namespace std;
unsigned long long MOD = 1000000007;
const int MAXN = 22;
struct matrix {
  int n, m;
  unsigned long long arr[MAXN][MAXN];
  matrix() {}
  matrix(int x, int y, int V = 0) {
    n = x;
    m = y;
    for (int j = 0; j < n; j++)
      for (int i = 0; i < m; i++) arr[j][i] = V;
  }
  matrix(int x, int y, unsigned long long A[MAXN][MAXN]) {
    n = x;
    m = y;
    for (int j = 0; j < n; j++)
      for (int i = 0; i < m; i++) arr[j][i] = A[j][i];
  }
  matrix operator*(matrix &mat) {
    matrix res(n, mat.m, 0);
    unsigned long long theta;
    for (int j = 0; j < n; j++) {
      for (int i = 0; i < mat.m; i++) {
        theta = 0;
        for (int k = 0; k < m; k++) {
          theta += 1ll * arr[j][k] * mat.arr[k][i];
          theta %= MOD;
        }
        res.arr[j][i] = theta;
      }
    }
    return res;
  }
  matrix power(unsigned long long K) {
    matrix res(n, m, 0), b(n, m, 0);
    for (int j = 0; j < n; j++) res.arr[j][j] = 1ll;
    b = (*this);
    while (K > 0) {
      if ((K & 1)) res = res * b;
      K /= 2;
      b = b * b;
    }
    return res;
  }
};
void print(matrix &G) {
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) cout << G.arr[i][j] << ' ';
    cout << endl;
  }
}
int main() {
  int n;
  unsigned long long k;
  cin >> n >> k;
  matrix M(20, 20, 0);
  for (int i = 0; i < 20; i++) M.arr[i][i] = 1ll;
  for (int u = 0; u < n; u++) {
    int c;
    unsigned long long a, b;
    cin >> a >> b >> c;
    matrix G(20, 20, 0);
    for (int i = 0; i < 20; i++)
      for (int j = 0; j < 20; j++) {
        if (abs(j - i) <= 1 && j <= c && i <= c) G.arr[i][j] = 1ll;
      }
    if (min(b, k) - a == 0) continue;
    G = G.power(min(b, k) - a);
    M = M * G;
  }
  unsigned long long sum = M.arr[0][0] % MOD;
  cout << sum << endl;
  return 0;
}
