#include <bits/stdc++.h>
using namespace std;
int M[16][64][16][16];
int X[16], Y[16], *A, *B, *C;
int main() {
  for (int n = 0; n <= 15; n++) {
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= n; j++) M[n][0][i][j] = (i < j ? j - i : i - j) < 2;
    for (int e = 1; e <= 63; e++)
      for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
          for (int k = 0; k <= n; k++)
            M[n][e][i][j] = (M[n][e][i][j] +
                             M[n][e - 1][i][k] * (long long)M[n][e - 1][k][j]) %
                            1000000007;
  }
  long long x, y, z;
  *(A = X) = 1;
  B = Y;
  int q, n, e;
  for (cin >> q >> z; q--;) {
    cin >> x >> y >> n;
    if (y > z) y = z;
    for (x = y - x, e = 0; x; x >>= 1, ++e)
      if (x & 1) {
        for (int i = 0; i <= n; i++) {
          B[i] = 0;
          for (int j = 0; j <= n; j++)
            B[i] = (B[i] + M[n][e][i][j] * (long long)A[j]) % 1000000007;
        }
        C = A;
        A = B;
        B = C;
      }
    for (int i = n + 1; i <= 15; i++) A[i] = 0;
  }
  cout << A[0];
}
