#include <bits/stdc++.h>

using namespace std;

#define ll long long int

typedef vector <int> vi;
typedef pair<int,int> ii;
typedef vector <vi> vvi;
typedef vector <ll> vll;
typedef vector <bool> vb;

#define f(i,j,n) for(int i=j;i<n;i++)
#define ff(i,j,n) for(int i=j;i>=n;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define testcase int t; cin>>t; while(t--)

const ll mod = 1000000000LL + 7LL;

struct mx
{
    int a[16][16];
}ans,p;

ll n,k;
ll aa[101],b[101],c[101];

mx mult(mx x,mx y)
{
    mx z;
    memset(z.a,0,sizeof(z.a));
    f(i,1,16)
        f(j,1,16)
            f(k,1,16)
                z.a[i][j] = (z.a[i][j] + 1LL*x.a[i][k]*y.a[k][j] ) % mod;

    return z;
}

mx mul(mx x,ll y)
{
    mx z;
    memset(z.a,0,sizeof(z.a));
        f(i,1,16) z.a[i][i]=1;
    while(y)
    {
        if(y%2 == 1) z = mult(z,x);
        x = mult(x,x);
        y/=2;
    }
    return z;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin>>n>>k;
	f(i,1,n+1)
	cin>>aa[i]>>b[i]>>c[i];

	memset(ans.a,0,sizeof(ans.a));

	f(i,1,16) ans.a[i][i]=1LL;

	f(i,1,n+1)
	{
	    memset(p.a,0,sizeof(p.a));
	    //cout<<c[i]<<" ";
	    f(j,1,c[i]+2)
	        f(k,1,c[i]+2)
	            {
	                if(labs(j-k) <= 1) p.a[j][k]=1;
	                //if(i==1)
	                //cout<<j<<" "<<k<<"\n";
	            }
	   //cout<<p.a[1][1]<<" ";
	   if(i==n)
	   p = mul(p,k-aa[i]);
	   else
	   p = mul(p,b[i]-aa[i]);

	   ans = mult(p,ans);

	}
	cout<<ans.a[1][1];
  	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

typedef vector <int> vi;
typedef pair<int,int> ii;
typedef vector <vi> vvi;
typedef vector <ll> vll;
typedef vector <bool> vb;

#define f(i,j,n) for(int i=j;i<n;i++)
#define ff(i,j,n) for(int i=j;i>=n;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define testcase int t; cin>>t; while(t--)

const ll mod = 1000000000LL + 7LL;

struct mx
{
    ll a[18][18];
}ans,p;

ll n,k;
ll aa[101],b[101],c[101];

mx mult(mx x,mx y)
{
    mx z;
    memset(z.a,0LL,sizeof(z.a));
    f(i,1,17)
        f(j,1,17)
            f(k,1,17)
                z.a[i][j] = (z.a[i][j] + (1LL * x.a[i][k] * y.a[k][j]) % mod ) % mod;

    return z;
}

mx mul(mx x,ll y)
{
    mx z;
    memset(z.a,0LL,sizeof(z.a));
        f(i,1,17) z.a[i][i]=1LL;
    while(y)
    {
        if(y%2LL == 1LL) z = mult(z,x);
        x = mult(x,x);
        y/=2LL;
    }
    return z;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin>>n>>k;
	f(i,1,n+1)
	cin>>aa[i]>>b[i]>>c[i];

	memset(ans.a,0LL,sizeof(ans.a));

	f(i,1,17) ans.a[i][i]=1LL;

	f(i,1,n+1)
	{
	    memset(p.a,0LL,sizeof(p.a));
	    //cout<<c[i]<<" ";
	    f(j,1LL,c[i]+2LL)
	        f(k,1LL,c[i]+2LL)
	            {
	                if(labs(j-k) <= 1LL) p.a[j][k]=1LL;
	                //if(i==1)
	                //cout<<j<<" "<<k<<"\n";
	            }
	   //cout<<p.a[1][1]<<" ";
	   if(i==n)
	   p = mul(p,k-aa[i]);
	   else
	   p = mul(p,b[i]-aa[i]);

	   ans = mult(p,ans);

	}
	cout<<ans.a[1][1];
  	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

typedef vector <int> vi;
typedef pair<int,int> ii;
typedef vector <vi> vvi;
typedef vector <ll> vll;
typedef vector <bool> vb;

#define f(i,j,n) for(int i=j;i<n;i++)
#define ff(i,j,n) for(int i=j;i>=n;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define testcase int t; cin>>t; while(t--)

const ll mod = 1000000000LL + 7LL;

ll n,k;
ll ca[17],a,b,c,d,e,tmp[17],ret,kaka;
ll ch[]={-1,0,1};

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
			ca[0]=1;
	cin>>n>>k;
	d=16;
	ret=1;

	while(n-- && ret)
	{
		cin>>a>>b>>c;
		e = min(d,c);

		if(b>k)
		b=k,ret=0;

		f(i,e+1,16)
		ca[i]=0;
		if(a==0)
		a=1;
		f(ka,a,b)
		{

			f(i,0,16)
			tmp[i]=ca[i],ca[i]=0;

			if(ka==a)
			kaka  =  min(16LL,e+1);
			else
			kaka  =  min(16LL,c+1);
			f(i,0,kaka)
			{
				f(j,0,3)
				{
					if(ch[j]+i>=0 && ch[j]+i<=15)
					{
					ca[i] += tmp[i+ch[j]];
					// if(i==0)
					// cout<<tmp[i+ch[j]]<<" ";
					}
				}
				// if(i==0)
				// cout<<ca[i]<<"\n";
			}
			// f(i,0,3)
			// cout<<ca[i]<<" ";
			// cout<<"\n";
		}

		d = c;

	}
	f(i,0,16)
	tmp[i]=ca[i],ca[i]=0;
	f(i,0,16)
	{
		f(j,0,3)
		{
			if(ch[j]+i>=0 && ch[j]+i<=15)
			{
			ca[i] += tmp[i+ch[j]];
			// if(i==0)
			// cout<<tmp[i+ch[j]]<<" ";
			}
		}
		// if(i==0)
		// cout<<ca[i]<<"\n";
	}
	// f(i,0,3)
	// cout<<ca[i]<<" ";
	// cout<<"\n";
	cout<<ca[0];
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

typedef vector <int> vi;
typedef pair<int,int> ii;
typedef vector <vi> vvi;
typedef vector <ll> vll;
typedef vector <bool> vb;

#define f(i,j,n) for(int i=j;i<n;i++)
#define ff(i,j,n) for(int i=j;i>=n;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define testcase int t; cin>>t; while(t--)

const ll mod = 1000000000LL + 7LL;

ll n,k;
ll ca[17],a,b,c,d,e,tmp[17],ret,kaka;
ll ch[]={-1,0,1};

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
			ca[0]=1;
	cin>>n>>k;
	d=16;
	ret=1;

	while(n-- && ret)
	{
		cin>>a>>b>>c;
		e = min(d,c);

		if(b>k)
		b=k,ret=0;

		f(i,e+1,16)
		ca[i]=0;
		if(a==0)
		a=1;
		f(ka,a,b)
		{

			f(i,0,16)
			tmp[i]=ca[i],ca[i]=0;

			if(ka==a)
			kaka  =  min(16LL,e+1);
			else
			kaka  =  min(16LL,c+1);
			f(i,0,kaka)
			{
				f(j,0,3)
				{
					if(ch[j]+i>=0 && ch[j]+i<=15)
					{
					ca[i] += tmp[i+ch[j]];
					// if(i==0)
					// cout<<tmp[i+ch[j]]<<" ";
					}
				}
				// if(i==0)
				// cout<<ca[i]<<"\n";
			}
			// f(i,0,3)
			// cout<<ca[i]<<" ";
			// cout<<"\n";
		}

		d = c;

	}
	f(i,0,16)
	tmp[i]=ca[i],ca[i]=0;
	f(i,0,kaka)
	{
		f(j,0,3)
		{
			if(ch[j]+i>=0 && ch[j]+i<=15)
			{
			ca[i] += tmp[i+ch[j]];
			// if(i==0)
			// cout<<tmp[i+ch[j]]<<" ";
			}
		}
		// if(i==0)
		// cout<<ca[i]<<"\n";
	}
	// f(i,0,3)
	// cout<<ca[i]<<" ";
	// cout<<"\n";
	cout<<ca[0];
	return 0;
}


#include <iostream>
using namespace std;

#define MOD 1000000007
#define MAX 16
#define plus(a, b) a = (a+(b))%MOD

typedef long long ll;
ll n, k, i, j, a, b, c;
ll m[MAX][MAX] = {}, tmp[MAX][MAX] = {};
ll t[64][MAX][MAX] = {};

// pl = a*b
void mmul(ll pl[MAX][MAX], ll a[MAX][MAX], ll b[MAX][MAX]) {
    int r, c, i;
    for (r = 0; r < MAX; r++) {
        for (c = 0; c < MAX; c++) {
            ll dp = 0;
            // dot product
            for (i = 0; i < MAX; i++) plus(dp, a[r][i]*b[i][c]);
            pl[r][c] = dp;
        }
    }
}

// a = b
void cp(ll a[MAX][MAX], ll b[MAX][MAX]) {
    int r, c;
    for (r = 0; r < MAX; r++) for (c = 0; c < MAX; c++) a[r][c] = b[r][c];
}

int main() {
    cin >> n >> k;
    for (i = 0; i < MAX; i++) m[i][0] = 1;
    for (i = 0; i < n; i++) {
        cin >> a >> b >> c;
        if (a >= k) break;
        b = min(b, k);

        // create transformation matrix of (c+1)^2
        for (j = 0; j < MAX; j++) for (int k = 0; k < MAX; k++) t[0][j][k] = 0;
        for (j = 0; j < c+1; j++) {
            for (int k = 0; k < c+1; k++) {
                t[0][j][k] = (j-1 <= k && k <= j+1);
            }
        }

        // generate powers of the transform matrix
        for (j = 1; j < 64; j++) mmul(t[j], t[j-1], t[j-1]);

        // crop existing matrix
        for (j = 0; j < MAX; j++) for (int k = 0; k < MAX; k++) if (k > c) m[j][k] = 0;

        // perform multiplication
        ll p = b-a;
        for (j = 0; j < 64; j++) {
            if (p & ((ll)1<<j)) mmul(tmp, m, t[j]), cp(m, tmp);
        }
    }
    cout << m[0][0] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define INF 0x3f3f3f3fLL
typedef long long ll;
const ll mod = 1e9 + 7;
int a[105], b[105], c[105];
struct Martix{
    ll a[20][20];
    void print(int n){
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++) cout << a[i][j] << ' ';
            cout << endl;
        }
    }
};
Martix mul(Martix m1, Martix m2, int& n){
    Martix ret;
    memset(ret.a, 0, sizeof(ret.a));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            for (int k = 0; k < n; k++){
                ret.a[i][j] += m1.a[i][k] * m2.a[k][j] + mod;
                ret.a[i][j] %= mod;
            }
        }
    }
    return ret;
}
Martix pow(Martix m, int p, int n){
    Martix ret;
    memset(ret.a, 0, sizeof(ret.a));
    for (int i = 0; i < n; i++) ret.a[i][i] = 1;
    while (p){
        if (p & 1) ret = mul(ret, m, n);
        m = mul(m, m, n);
        p >>= 1;
    }
    return ret;
}
vector<int> mul(Martix m, vector<int> k, int n){
    vector<int>ret;
    ret.resize(20);
    for (int i = 0; i < n; i++){
        ret[i] = 0;
        for (int j = 0; j < n; j++){
            ret[i] += m.a[i][j] * k[j] + mod;
            ret[i] %= mod;
        }
    }
    for (int i = n; i < 20; i++) ret[i] = 0;
    return ret;
}
Martix getMartix(int n){
    Martix ret;
    memset(ret.a, 0, sizeof(ret.a));
    for (int i = 0; i < n; i++){
        for (int j = max(0, i - 1); j <= min(n, i + 1); j++){
            ret.a[i][j] = 1;
        }
    }
    return ret;
}
vector<int> solve(vector<int> ans, int i){
    Martix m = getMartix(c[i] + 1);
    //m.print(c[i] + 1);
    m = pow(m, b[i] - a[i], c[i] + 1);
    //m.print(c[i] + 1);
    return mul(m, ans, c[i] + 1);
}
int main(){
    //ios::sync_with_stdio(0);
    int n, k; cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    b[n - 1] = k;
    vector<int>ans; ans.resize(20);
    ans[0] = 1;
    for (int i = 0; i < n; i++){
        ans = solve(ans, i);
    }
    cout << ans[0] << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define INF 0x3f3f3f3fLL
typedef long long ll;
const ll mod = 1e9 + 7;
#define int long long
int a[105], b[105], c[105];
struct Martix{
    ll a[20][20];
    void print(int n){
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++) cout << a[i][j] << ' ';
            cout << endl;
        }
    }
};
Martix mul(Martix m1, Martix m2, int& n){
    Martix ret;
    memset(ret.a, 0, sizeof(ret.a));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            for (int k = 0; k < n; k++){
                ret.a[i][j] += m1.a[i][k] * m2.a[k][j] + mod;
                ret.a[i][j] %= mod;
            }
        }
    }
    return ret;
}
Martix pow(Martix m, int p, int n){
    Martix ret;
    memset(ret.a, 0, sizeof(ret.a));
    for (int i = 0; i < n; i++) ret.a[i][i] = 1;
    while (p){
        if (p & 1) ret = mul(ret, m, n);
        m = mul(m, m, n);
        p >>= 1;
    }
    return ret;
}
vector<int> mul(Martix m, vector<int> k, int n){
    vector<int>ret;
    ret.resize(20);
    for (int i = 0; i < n; i++){
        ret[i] = 0;
        for (int j = 0; j < n; j++){
            ret[i] += m.a[i][j] * k[j] + mod;
            ret[i] %= mod;
        }
    }
    for (int i = n; i < 20; i++) ret[i] = 0;
    return ret;
}
Martix getMartix(int n){
    Martix ret;
    memset(ret.a, 0, sizeof(ret.a));
    for (int i = 0; i < n; i++){
        for (int j = max(0, i - 1); j <= min(n, i + 1); j++){
            ret.a[i][j] = 1;
        }
    }
    return ret;
}
vector<int> solve(vector<int> ans, int i){
    Martix m = getMartix(c[i] + 1);
    //m.print(c[i] + 1);
    m = pow(m, b[i] - a[i], c[i] + 1);
    //m.print(c[i] + 1);
    return mul(m, ans, c[i] + 1);
}
main(){
    //ios::sync_with_stdio(0);
    int n, k; cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    b[n - 1] = k;
    vector<int>ans; ans.resize(20);
    ans[0] = 1;
    for (int i = 0; i < n; i++){
        ans = solve(ans, i);
    }
    cout << ans[0] << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define INF 0x3f3f3f3fLL
typedef long long ll;
const ll mod = 1e9 + 7;
int a[105], b[105], c[105];
struct Martix{
    ll a[20][20];
    void print(int n){
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++) cout << a[i][j] << ' ';
            cout << endl;
        }
    }
};
Martix mul(Martix& m1, Martix& m2, int& n){
    Martix ret;
    memset(ret.a, 0, sizeof(ret.a));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            for (int k = 0; k < n; k++){
                ret.a[i][j] += m1.a[i][k] * m2.a[k][j] + mod;
                ret.a[i][j] %= mod;
            }
        }
    }
    return ret;
}
Martix pow(Martix& m, int n){
    Martix ret;
    memset(ret.a, 0, sizeof(ret.a));
    for (int i = 0; i < n; i++) ret.a[i][i] = 1;
    while (n){
        if (n & 1) ret = mul(ret, m, n);
        ret = mul(ret, ret, n);
        n >>= 1;
    }
    return ret;
}
vector<int> mul(Martix& m, vector<int>& k, int n){
    vector<int>ret;
    ret.resize(20);
    for (int i = 0; i < n; i++){
        ret[i] = 0;
        for (int j = 0; j < n; j++){
            ret[i] += m.a[i][j] * k[j] + mod;
            ret[i] %= mod;
        }
    }
    for (int i = n; i < 20; i++) ret[i] = 0;
    return ret;
}
Martix getMartix(int n){
    Martix ret;
    memset(ret.a, 0, sizeof(ret.a));
    for (int i = 0; i < n; i++){
        for (int j = max(0, i - 1); j <= min(n, i + 1); j++){
            ret.a[i][j] = 1;
        }
    }
    return ret;
}
vector<int> solve(vector<int>& ans, int i){
    Martix m = getMartix(c[i] + 1);
    //m.print(c[i] + 1);
    m = pow(m, b[i] - a[i]);
    //m.print(c[i] + 1);
    return mul(m, ans, c[i] + 1);
}
int main(){
    ios::sync_with_stdio(0);
    int n, k; cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    b[n - 1] = k;
    vector<int>ans; ans.resize(20);
    ans[0] = 1;
    for (int i = 0; i < n; i++){
        ans = solve(ans, i);
    }
    cout << ans[0] << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define INF 0x3f3f3f3fLL
typedef long long ll;
const ll mod = 1e9 + 7;
#define int long long
int a[105], b[105], c[105];
struct Martix{
    ll a[20][20];
    void print(int n){
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++) cout << a[i][j] << ' ';
            cout << endl;
        }
    }
};
Martix mul(Martix m1, Martix m2, int& n){
    Martix ret;
    memset(ret.a, 0, sizeof(ret.a));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            for (int k = 0; k < n; k++){
                ret.a[i][j] += m1.a[i][k] * m2.a[k][j] + mod;
                ret.a[i][j] %= mod;
            }
        }
    }
    return ret;
}
Martix pow(Martix m, int p, int n){
    Martix ret;
    memset(ret.a, 0, sizeof(ret.a));
    for (int i = 0; i < n; i++) ret.a[i][i] = 1;
    while (p){
        if (p & 1) ret = mul(ret, m, n);
        m = mul(m, m, n);
        p >>= 1;
    }
    return ret;
}
vector<int> mul(Martix m, vector<int> k, int n){
    vector<int>ret;
    ret.resize(20);
    for (int i = 0; i < n; i++){
        ret[i] = 0;
        for (int j = 0; j < n; j++){
            ret[i] += m.a[i][j] * k[j] + mod;
            ret[i] %= mod;
        }
    }
    for (int i = n; i < 20; i++) ret[i] = 0;
    return ret;
}
Martix getMartix(int n){
    Martix ret;
    memset(ret.a, 0, sizeof(ret.a));
    for (int i = 0; i < n; i++){
        for (int j = max(0LL, i - 1); j <= min(n, i + 1); j++){
            ret.a[i][j] = 1;
        }
    }
    return ret;
}
vector<int> solve(vector<int> ans, int i){
    Martix m = getMartix(c[i] + 1);
    //m.print(c[i] + 1);
    m = pow(m, b[i] - a[i], c[i] + 1);
    //m.print(c[i] + 1);
    return mul(m, ans, c[i] + 1);
}
main(){
    //ios::sync_with_stdio(0);
    int n, k; cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    b[n - 1] = k;
    vector<int>ans; ans.resize(20);
    ans[0] = 1;
    for (int i = 0; i < n; i++){
        ans = solve(ans, i);
    }
    cout << ans[0] << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int mod = 1000000000 + 7;

typedef vector<vector<int> > matrix;
typedef vector<int> row;

matrix getMatrix(int size) {
	matrix res(size, row(size));
	for(int i = 0; i < size; ++i)
		for(int j = 0; j < size; ++j)
			res[i][j] = (abs(i - j) <= 1 ? 1 : 0);
	return res;
}

matrix matrixMultiply(const matrix &a, const matrix &b) {
	matrix res(a.size(), row(b[0].size()));
	for(int i = 0; i < a.size(); ++i) {
		for(int j = 0; j < b[0].size(); ++j) {
			long long cur = 0;
			for(int k = 0; k < b.size(); ++k)
				cur += 1LL * a[i][k] * b[k][j];
			res[i][j] = cur % mod;
		}
	}
	return res;
}

matrix binPow(const matrix &a, long long n) {
	if(n == 1)
		return a;

	matrix b = binPow(a, n / 2);
	matrix res = matrixMultiply(b, b);
	if(n & 1)
	    res = matrixMultiply(res, a);
	return res;
}

long long a[101], b[101], c[101];

matrix dp(1, row(1));

int main() {
	int n;
	long long k;
	cin >> n >> k;

	for(int i = 0; i < n; ++i)
		cin >> a[i] >> b[i] >> c[i];

	dp[0][0] = 1;
	for(int i = 0; i < n; ++i) {
		dp.resize(c[i] + 1, vector<int>{0});
		long long len = min(b[i], k) - a[i];

		matrix mul = getMatrix(c[i] + 1);
		dp = matrixMultiply(binPow(mul, len), dp);
	}

	cout << dp[0][0];
}


#include <bits/stdc++.h>

using namespace std;

const int mod = 1000000000 + 7;

typedef vector<vector<int> > matrix;
typedef vector<int> row;

matrix getMatrix(int size) {
	matrix res(size, row(size));
	for(int i = 0; i < size; ++i)
		for(int j = 0; j < size; ++j)
			res[i][j] = (abs(i - j) <= 1 ? 1 : 0);
	return res;
}

matrix matrixMultiply(const matrix &a, const matrix &b) {
	matrix res(a.size(), row(b[0].size()));
	for(int i = 0; i < a.size(); ++i) {
		for(int j = 0; j < b[0].size(); ++j) {
			res[i][j] = 0;
			for(int k = 0; k < b.size(); ++k) {
				res[i][j] += a[i][k] * b[k][j];
				res[i][j] %= mod;
			}
		}
	}
	return res;
}

matrix binPow(const matrix &a, long long n) {
	if(n <= 1)
		return a;

	matrix b = binPow(a, n / 2);
	matrix res = matrixMultiply(b, b);
	if(n & 1)
	    res = matrixMultiply(res, a);
	return res;
}

long long a[101], b[101], c[101];

matrix dp(1, row(1));

int main() {
	int n;
	long long k;
	cin >> n >> k;

	for(int i = 0; i < n; ++i)
		cin >> a[i] >> b[i] >> c[i];

	dp[0][0] = 1;
	for(int i = 0; i < n; ++i) {
		dp.resize(c[i] + 1, vector<int>{0});
		long long len = min(b[i], k) - a[i];

		matrix mul = getMatrix(c[i] + 1);
		mul = binPow(mul, len);
		dp = matrixMultiply(mul, dp);
	}

	cout << dp[0][0];
}


#include <bits/stdc++.h>

using namespace std;

const int mod = 1000000000 + 7;

typedef vector<vector<int> > matrix;
typedef vector<int> row;

matrix getMatrix(int size) {
	matrix res(size, row(size));
	for(int i = 0; i < size; ++i)
		for(int j = 0; j < size; ++j)
			res[i][j] = (abs(i - j) <= 1 ? 1 : 0);
	return res;
}

matrix matrixMultiply(matrix &a, matrix &b) {
	matrix res(a.size(), row(b[0].size()));
	for(int i = 0; i < a.size(); ++i) {
		for(int j = 0; j < b[0].size(); ++j) {
			res[i][j] = 0;
			for(int k = 0; k < b.size(); ++k) {
				res[i][j] += a[i][k] * b[k][j];
				res[i][j] %= mod;
			}
		}
	}
	return res;
}

matrix binPow(matrix &a, long long n) {
	if(n == 1)
		return a;

	matrix b = binPow(a, n / 2);
	matrix res = matrixMultiply(b, b);
	if(n & 1)
	    res = matrixMultiply(res, a);
	return res;
}

long long a[101], b[101], c[101];

matrix dp(1, row(1));

int main() {
	int n;
	long long k;
	cin >> n >> k;

	for(int i = 0; i < n; ++i)
		cin >> a[i] >> b[i] >> c[i];

	dp[0][0] = 1;
	for(int i = 0; i < n; ++i) {
		dp.resize(c[i] + 1, vector<int>{0});
		long long len = min(b[i], k) - a[i];

		matrix mul = getMatrix(c[i] + 1);
		dp = matrixMultiply(binPow(mul, len), dp);
	}

	cout << dp[0][0];
}


#include <bits/stdc++.h>

using namespace std;

const int mod = 1000000000 + 7;

typedef vector<vector<int> > matrix;
typedef vector<int> row;

matrix getMatrix(int size) {
	matrix res(size, row(size));
	for(int i = 0; i < size; ++i)
		for(int j = 0; j < size; ++j)
			res[i][j] = (abs(i - j) <= 1 ? 1 : 0);
	return res;
}

matrix matrixMultiply(const matrix &a, const matrix &b) {
	matrix res(a.size(), row(b[0].size()));
	for(int i = 0; i < a.size(); ++i) {
		for(int j = 0; j < b[0].size(); ++j) {
			res[i][j] = 0;
			for(int k = 0; k < b.size(); ++k) {
				res[i][j] += a[i][k] * b[k][j];
				res[i][j] %= mod;
			}
		}
	}
	return res;
}

matrix binPow(const matrix &a, long long n) {
	if(n <= 1)
		return a;

	matrix b = binPow(a, n / 2);
	matrix res = matrixMultiply(b, b);
	if(n & 1)
	    res = matrixMultiply(res, a);
	return res;
}

long long a[101], b[101], c[101];

matrix dp(1, row(1));

int main() {
	int n;
	long long k;
	cin >> n >> k;

	for(int i = 0; i < n; ++i)
		cin >> a[i] >> b[i] >> c[i];

	dp[0][0] = 1;
	for(int i = 0; i < n; ++i) {
		dp.resize(c[i] + 1, vector<int>{0});
		long long len = min(b[i], k) - a[i];

		if(len > 0) {
		    matrix mul = getMatrix(c[i] + 1);
		    dp = matrixMultiply(binPow(mul, len), dp);
		}
	}

	cout << dp[0][0];
}


#include <bits/stdc++.h>

using namespace std;

const long long mod = 1000000007LL;

typedef vector<vector<int> > matrix;
typedef vector<int> row;

matrix getMatrix(int size) {
	matrix res(size, row(size));
	for(int i = 0; i < size; ++i)
		for(int j = 0; j < size; ++j)
			res[i][j] = (abs(i - j) <= 1 ? 1 : 0);
	return res;
}

matrix matrixMultiply(const matrix &a, const matrix &b) {
	matrix res(a.size(), row(b[0].size()));
	for(int i = 0; i < a.size(); ++i) {
		for(int j = 0; j < b[0].size(); ++j) {
			long long cur = 0;
			for(int k = 0; k < b.size(); ++k) {
				cur += 1LL * a[i][k] * b[k][j];
				cur %= mod;
			}
			res[i][j] = cur % mod;
		}
	}
	return res;
}

matrix binPow(const matrix &a, long long n) {
	if(n <= 1)
		return a;

	matrix b = binPow(a, n / 2);
	matrix res = matrixMultiply(b, b);
	if(n & 1)
	    res = matrixMultiply(res, a);
	return res;
}

long long a[101], b[101], c[101];

matrix dp(1, row(1));

int main() {
	int n;
	long long k;
	cin >> n >> k;

	for(int i = 0; i < n; ++i)
		cin >> a[i] >> b[i] >> c[i];

	dp[0][0] = 1;
	for(int i = 0; i < n; ++i) {
		dp.resize(c[i] + 1, vector<int>{0});
		long long len = min(b[i], k) - a[i];

		if(len > 0) {
		    matrix mul = getMatrix(c[i] + 1);
		    dp = matrixMultiply(binPow(mul, len), dp);
		}
	}

	cout << dp[0][0];
}


#include <bits/stdc++.h>

using namespace std;

const int mod = 1000000000 + 7;

typedef vector<vector<int> > matrix;
typedef vector<int> row;

matrix getMatrix(int size) {
	matrix res(size, row(size));
	for(int i = 0; i < size; ++i)
		for(int j = 0; j < size; ++j)
			res[i][j] = (abs(i - j) <= 1 ? 1 : 0);
	return res;
}

matrix matrixMultiply(matrix a, matrix b) {
	matrix res(a.size(), row(b[0].size()));
	for(int i = 0; i < a.size(); ++i) {
		for(int j = 0; j < b[0].size(); ++j) {
			res[i][j] = 0;
			for(int k = 0; k < b.size(); ++k) {
				res[i][j] += a[i][k] * b[k][j];
				res[i][j] %= mod;
			}
		}
	}
	return res;
}

matrix binPow(matrix a, long long n) {
	if(n == 1)
		return a;
	if(n & 1)
		return matrixMultiply(binPow(a, n - 1), a);
	matrix b = binPow(a, n / 2);
	return matrixMultiply(b, b);
}

long long a[101], b[101], c[101];

matrix dp(1, row(1));

int main() {
	int n;
	long long k;
	cin >> n >> k;

	for(int i = 0; i < n; ++i)
		cin >> a[i] >> b[i] >> c[i];

	dp[0][0] = 1;
	for(int i = 0; i < n; ++i) {
		dp.resize(c[i] + 1, vector<int>{0});
		long long len = min(b[i], k) - a[i];

		matrix mul = getMatrix(c[i] + 1);
		dp = matrixMultiply(binPow(mul, len), dp);
	}

	cout << dp[0][0];
}


#include <bits/stdc++.h>

using namespace std;

const long long mod = 1000000007LL;

typedef vector<vector<int> > matrix;
typedef vector<int> row;

matrix getMatrix(int size) {
	matrix res(size, row(size));
	for(int i = 0; i < size; ++i)
		for(int j = 0; j < size; ++j)
			res[i][j] = (abs(i - j) <= 1 ? 1 : 0);
	return res;
}

matrix matrixMultiply(const matrix &a, const matrix &b) {
	matrix res(a.size(), row(b[0].size()));
	for(int i = 0; i < a.size(); ++i) {
		for(int j = 0; j < b[0].size(); ++j) {
			long long cur = 0;
			for(int k = 0; k < b.size(); ++k) {
				cur += 1LL * a[i][k] * b[k][j];
				cur %= mod;
			}
			res[i][j] = cur % mod;
		}
	}
	return res;
}

matrix binPow(const matrix &a, long long n) {
	if(n == 1)
		return a;

	matrix b = binPow(a, n / 2);
	matrix res = matrixMultiply(b, b);
	if(n & 1)
	    res = matrixMultiply(res, a);
	return res;
}

long long a[101], b[101], c[101];

matrix dp(1, row(1));

int main() {
	int n;
	long long k;
	cin >> n >> k;

	for(int i = 0; i < n; ++i)
		cin >> a[i] >> b[i] >> c[i];

	dp[0][0] = 1;
	for(int i = 0; i < n; ++i) {
		dp.resize(c[i] + 1, vector<int>{0});
		long long len = min(b[i], k) - a[i];

		matrix mul = getMatrix(c[i] + 1);
		dp = matrixMultiply(binPow(mul, len), dp);
	}

	cout << dp[0][0];
}


#include <bits/stdc++.h>

using namespace std;

const int mod = 1000000000 + 7;

typedef vector<vector<int> > matrix;
typedef vector<int> row;

matrix getMatrix(int size) {
	matrix res(size, row(size));
	for(int i = 0; i < size; ++i)
		for(int j = 0; j < size; ++j)
			res[i][j] = (abs(i - j) <= 1 ? 1 : 0);
	return res;
}

matrix matrixMultiply(const matrix &a, const matrix &b) {
	matrix res(a.size(), row(b[0].size()));
	for(int i = 0; i < a.size(); ++i) {
		for(int j = 0; j < b[0].size(); ++j) {
			res[i][j] = 0;
			for(int k = 0; k < b.size(); ++k) {
				res[i][j] += a[i][k] * b[k][j];
				res[i][j] %= mod;
			}
		}
	}
	return res;
}

matrix binPow(const matrix &a, long long n) {
	if(n == 1)
		return a;

	matrix b = binPow(a, n / 2);
	matrix res = matrixMultiply(b, b);
	if(n & 1)
	    res = matrixMultiply(res, a);
	return res;
}

long long a[101], b[101], c[101];

matrix dp(1, row(1));

int main() {
	int n;
	long long k;
	cin >> n >> k;

	for(int i = 0; i < n; ++i)
		cin >> a[i] >> b[i] >> c[i];

	dp[0][0] = 1;
	for(int i = 0; i < n; ++i) {
		dp.resize(c[i] + 1, vector<int>{0});
		long long len = min(b[i], k) - a[i];

		matrix mul = getMatrix(c[i] + 1);
		dp = matrixMultiply(binPow(mul, len), dp);
	}

	cout << dp[0][0];
}


#include <bits/stdc++.h>

using namespace std;

const int mod = 1000000000 + 7;

typedef vector<vector<int> > matrix;
typedef vector<int> row;

matrix getMatrix(int size) {
	matrix res(size, row(size));
	for(int i = 0; i < size; ++i)
		for(int j = 0; j < size; ++j)
			res[i][j] = (abs(i - j) <= 1 ? 1 : 0);
	return res;
}

matrix matrixMultiply(const matrix &a, const matrix &b) {
	matrix res(a.size(), row(b[0].size()));
	for(int i = 0; i < a.size(); ++i) {
		for(int j = 0; j < b[0].size(); ++j) {
			long long cur = 0;
			for(int k = 0; k < b.size(); ++k)
				cur += 1LL * a[i][k] * b[k][j];
			res[i][j] = cur % mod;
		}
	}
	return res;
}

matrix binPow(const matrix &a, long long n) {
	if(n <= 1)
		return a;

	matrix b = binPow(a, n / 2);
	matrix res = matrixMultiply(b, b);
	if(n & 1)
	    res = matrixMultiply(res, a);
	return res;
}

long long a[101], b[101], c[101];

matrix dp(1, row(1));

int main() {
	int n;
	long long k;
	cin >> n >> k;

	for(int i = 0; i < n; ++i)
		cin >> a[i] >> b[i] >> c[i];

	dp[0][0] = 1;
	for(int i = 0; i < n; ++i) {
		dp.resize(c[i] + 1, vector<int>{0});
		long long len = min(b[i], k) - a[i];

		if(len > 0) {
		    matrix mul = getMatrix(c[i] + 1);
		    dp = matrixMultiply(binPow(mul, len), dp);
		}
	}

	cout << dp[0][0];
}


#define DM 17
#define DN 101
#include <iostream>
using namespace std;

long long dpaux[DM], dp[DM], mat[DM][DM], morg[DM][DM], n, a[DM], b[DM], c[DM], k;

void inmultire(long long m1[DM][DM], long long m2[DM][DM], long long aux[DM][DM], long long lg)
{
	for (long long i = 1; i <= lg; ++i)
		for (long long j = 1; j <= lg; ++j)
			for (long long l = 1; l <= lg; ++l)
				aux[i][j]+=m1[i][l]*m2[l][j];
}

void lgput(long long rezultat[DM][DM], long long lg, long long exp)
{
	long long aux1[DM][DM];
	for (int i = 1; i <= lg; ++i)
		for (int j = 1; j <= lg; ++j)
			aux1[i][j] = 0;

	if (exp == 1)
		for (long long i = 1; i <= lg; ++i)
			for (long long j = 1; j <= lg; ++j)
				rezultat[i][j] = morg[i][j];

	else if (exp%2 == 1)
	{
		lgput(aux1, lg, exp - 1);
		inmultire(morg, aux1, rezultat, lg);
	}

	else
	{
		lgput(aux1, lg, exp/2);
		inmultire(aux1, aux1, rezultat, lg);
	}
}

void rezultat (long long lg)
{
	for (int i = 1; i <= lg; ++i)
		dpaux[i] = 0;
	for (int i = 1; i <= lg; ++i)
		for (int j = 1; j <= lg; ++j)
			dpaux[i]+=mat[i][j]*dp[j];
	for (int i = 1; i <= lg; ++i)
		dp[i] = dpaux[i];
	for (int i = 1; i <= lg; ++i)
		for (int j = 1; j <= lg; ++j)
			mat[i][j] = 0;
}

int main()
{
	for (long long i = 1; i <= 16; ++i)
	{
		morg[i][i] = morg[i][i-1] = 1;
		if (i + 1 <= 16)
			morg[i][i+1] = 1;
	}
	cin >> n >> k;
	for (long long i = 1; i <= n; ++i)
		cin >> a[i] >> b[i] >> c[i];
	dp[1] = 1;
	for (long long i = 1; i <= n; ++i)
	{
		if (a[i] == k)
		{
			cout << dp[1];
			return 0;
		}
		lgput(mat, c[i] + 1, min(b[i], k) - a[i]);
		rezultat(c[i] + 1);
		for (long long j = c[i] + 2; j <= 15; ++j)
			dp[j] = 0;
	}
	cout << dp[1];
	return 0;
}


#define DM 17
#define DN 101
#define MD 1000000007
#include <iostream>
using namespace std;

long long dpaux[DM], dp[DM], mat[DM][DM], morg[DM][DM], n, a[DM], b[DM], c[DM], k, aux1[DM][DM];

void inmultire(long long m1[DM][DM], long long m2[DM][DM], long long aux[DM][DM], long long lg)
{
	for (int i = 1; i <= lg; ++i)
		for (int j = 1; j <= lg; ++j)
			aux[i][j] = 0;
	for (long long i = 1; i <= lg; ++i)
		for (long long j = 1; j <= lg; ++j)
			for (long long l = 1; l <= lg; ++l)
				aux[i][j]+=(m1[i][l]*m2[l][j])%MD;
}

void lgput(long long lg, long long exp)
{
	while (exp)
	{
		if (exp&1)
			inmultire(morg, aux1, mat, lg);
		intmultire(mat, mat, aux1);
		for (int i = 1; i <= lg; ++i)
			for (int j = 1; j <= lg; ++j)
				mat[i][j] = aux1[i][j];
		exp>>=1;
	}
}

void rezultat (long long lg)
{
	for (int i = 1; i <= lg; ++i)
		dpaux[i] = 0;
	for (int i = 1; i <= lg; ++i)
		for (int j = 1; j <= lg; ++j)
			dpaux[i]+=mat[i][j]*dp[j];
	for (int i = 1; i <= lg; ++i)
		dp[i] = dpaux[i]%MD;
	for (int i = 1; i <= lg; ++i)
		for (int j = 1; j <= lg; ++j)
			mat[i][j] = 0;
}

int main()
{
	for (long long i = 1; i <= 16; ++i)
	{
		morg[i][i] = morg[i][i-1] = 1;
		if (i + 1 <= 16)
			morg[i][i+1] = 1;
	}
	cin >> n >> k;
	for (long long i = 1; i <= n; ++i)
		cin >> a[i] >> b[i] >> c[i];
	dp[1] = 1;
	for (long long i = 1; i <= n; ++i)
	{
		if (a[i] == k)
		{
			cout << dp[1];
			return 0;
		}
		lgput(mat, c[i] + 1, min(b[i], k) - a[i]);
		rezultat(c[i] + 1);
		for (long long j = c[i] + 2; j <= 15; ++j)
			dp[j] = 0;
	}
	cout << dp[1];
	return 0;
}


#define DM 17
#define DN 101
#include <iostream>
using namespace std;

long long dp[DM], mat[DM][DM], morg[DM][DM], n, a[DM], b[DM], c[DM], k;

void inmultire(long long m1[DM][DM], long long m2[DM][DM], long long aux[DM][DM], long long lg)
{
	for (long long i = 1; i <= lg; ++i)
		for (long long j = 1; j <= lg; ++j)
			for (long long l = 1; l <= lg; ++l)
				aux[i][j]+=m1[i][l]*m2[l][j];
}

void lgput(long long rezultat[DM][DM], long long lg, long long exp)
{
	long long aux1[DM][DM], aux2[DM][DM];
	for (int i = 1; i <= lg; ++i)
		for (int j = 1; j <= lg; ++j)
			aux1[i][j] = aux2[i][j] = 0;

	if (exp == 1)
		for (long long i = 1; i <= lg; ++i)
			for (long long j = 1; j <= lg; ++j)
				rezultat[i][j] = morg[i][j];

	else if (exp%2 == 1)
	{
		lgput(aux1, lg, exp - 1);
		inmultire(morg, aux1, aux2, lg);
		for (long long i = 1; i <= lg; ++i)
			for (long long j = 1; j <= lg; ++j)
				rezultat[i][j] = aux2[i][j];
	}

	else
	{
		lgput(aux1, lg, exp/2);
		inmultire(aux1, aux1, aux2, lg);
		for (long long i = 1; i <= lg; ++i)
			for (long long j = 1; j <= lg; ++j)
				rezultat[i][j] = aux2[i][j];
	}
}

void rezultat (long long lg)
{
	long long dpaux[DM];
	for (int i = 1; i <= lg; ++i)
		dpaux[i] = 0;
	for (int i = 1; i <= lg; ++i)
		for (int j = 1; j <= lg; ++j)
			dpaux[i]+=mat[i][j]*dp[j];
	for (int i = 1; i <= lg; ++i)
		dp[i] = dpaux[i];
	for (int i = 1; i <= lg; ++i)
		for (int j = 1; j <= lg; ++j)
			mat[i][j] = 0;
}

int main()
{
	for (long long i = 1; i <= 16; ++i)
	{
		morg[i][i] = morg[i][i-1] = 1;
		if (i + 1 <= 16)
			morg[i][i+1] = 1;
	}
	cin >> n >> k;
	for (long long i = 1; i <= n; ++i)
		cin >> a[i] >> b[i] >> c[i];
	dp[1] = 1;
	for (long long i = 1; i <= n; ++i)
	{
		lgput(mat, c[i] + 1, min(b[i], k) - a[i]);
		rezultat(c[i] + 1);
		for (long long j = c[i] + 2; j <= 15; ++j)
			dp[j] = 0;
	}
	cout << dp[1];
	return 0;
}


#define DM 16
#define MD 1000000007
#include <iostream>
using namespace std;

long long n, a, b, c, k;
long long aux[DM][DM], m1[DM][DM], m2[DM][DM];

void inmultire(long long x[][DM], long long y[][DM])
{
	for (int i = 0; i < DM; ++i)
		for (int j = 0; j < DM; ++j)
		{
			aux[i][j] = 0;
			for (int l = 0; l < DM; ++l)
				aux[i][j]+=x[i][l]*y[l][j]%MD;
		}
	for (int i = 0; i < DM; ++i)
		for (int j = 0; j < DM; ++j)
			x[i][j] = aux[i][j]%MD;
}

void lgput (long long exp)
{
	while (exp)
	{
		if (exp&1)
			inmultire(m2, m1);
		inmultire(m1, m1);
		exp>>=1;
	}
}

void reset(long long lg)
{
	for (int i = 0; i < DM; ++i)
		for (int j = 0; j < DM; ++j)
			m1[i][j] = 0;
	for (int i = 0; i <= lg; ++i)
		for (int j = 0; j <= lg; ++j)
			m1[i][j] = (j >= i - 1 && j <= i + 1);
}

int main()
{
	cin >> n >> k;
	for (int i = 0; i < DM; ++i)
		m2[i][i] = 1;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a >> b >> c;
		b = min(b, k);
		reset(c);
		lgput(b - a);
	}
	cout << m2[0][0];
	return 0;
}


#define DM 17
#define DN 101
#include <iostream>
using namespace std;

long long dp[DM], mat[DM][DM], morg[DM][DM], n, a[DM], b[DM], c[DM], k;

void inmultire(long long m1[DM][DM], long long m2[DM][DM], long long aux[DM][DM], long long lg)
{
	for (long long i = 1; i <= lg; ++i)
		for (long long j = 1; j <= lg; ++j)
			for (long long l = 1; l <= lg; ++l)
				aux[i][j]+=m1[i][l]*m2[l][j];
}

void lgput(long long rezultat[DM][DM], long long lg, long long exp)
{
	long long aux1[DM][DM], aux2[DM][DM];
	for (int i = 1; i <= lg; ++i)
		for (int j = 1; j <= lg; ++j)
			aux1[i][j] = aux2[i][j] = 0;

	if (exp == 1)
		for (long long i = 1; i <= lg; ++i)
			for (long long j = 1; j <= lg; ++j)
				rezultat[i][j] = morg[i][j];

	else if (exp%2 == 1)
	{
		lgput(aux1, lg, exp - 1);
		inmultire(morg, aux1, aux2, lg);
		for (long long i = 1; i <= lg; ++i)
			for (long long j = 1; j <= lg; ++j)
				rezultat[i][j] = aux2[i][j];
	}

	else
	{
		lgput(aux1, lg, exp/2);
		inmultire(aux1, aux1, aux2, lg);
		for (long long i = 1; i <= lg; ++i)
			for (long long j = 1; j <= lg; ++j)
				rezultat[i][j] = aux2[i][j];
	}
}

void rezultat (long long lg)
{
	long long dpaux[DM];
	for (int i = 1; i <= lg; ++i)
		dpaux[i] = 0;
	for (int i = 1; i <= lg; ++i)
		for (int j = 1; j <= lg; ++j)
			dpaux[i]+=mat[i][j]*dp[j];
	for (int i = 1; i <= lg; ++i)
		dp[i] = dpaux[i];
	for (int i = 1; i <= lg; ++i)
		for (int j = 1; j <= lg; ++j)
			mat[i][j] = 0;
}

int main()
{
	for (long long i = 1; i <= 16; ++i)
	{
		morg[i][i] = morg[i][i-1] = 1;
		if (i + 1 <= 16)
			morg[i][i+1] = 1;
	}
	cin >> n >> k;
	for (long long i = 1; i <= n; ++i)
		cin >> a[i] >> b[i] >> c[i];
	dp[1] = 1;
	for (long long i = 1; i <= n; ++i)
	{
		if (a[i] == k)
		{
			cout << dp[1];
			return 0;
		}
		lgput(mat, c[i] + 1, min(b[i], k) - a[i]);
		rezultat(c[i] + 1);
		for (long long j = c[i] + 2; j <= 15; ++j)
			dp[j] = 0;
	}
	cout << dp[1];
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll n,k,a,b,c;

struct juzhen
{
ll m[18][18];
void clearit()//chushihua
  {
  int i;
  memset(m,0,sizeof(m));
  for (i=1;i<=15;i++)
    {
    m[i][i]=1;
	if (i) m[i][i-1]=1;
	if (i<15) m[i][i+1]=1;
	}
  }
}r,kong;

juzhen chengfa(juzhen a,juzhen b)
{
int i,j,k;
juzhen answer;
memset(answer.m,0,sizeof(answer.m));
for (i=1;i<=c+1;i++) for (j=1;j<=c+1;j++) for (k=1;k<=c+1;k++) answer.m[i][j]=(answer.m[i][j]+a.m[i][k]*b.m[k][j]+mod)%mod;
return answer;
}

juzhen quick_power(juzhen a,ll b)
{
if (b==0) return kong;
else if (b==1) return a;
juzhen result=quick_power(a,b/2);
return b&1?chengfa(chengfa(result,result),a):chengfa(result,result);
}

int main()
{
r.clearit();int i;
for (i=1;i<=15;i++) kong.m[i][i]=1;
bool okabe=0;juzhen answer;
memset(answer.m,0,sizeof(answer.m));
scanf("%I64d%I64d",&n,&k);
answer.m[1][1]=1;
for (i=1;i<=n;i++)
  {
  scanf("%I64d%I64d%I64d",&a,&b,&c),a++;
  if (k<b) b=k,okabe=1;
  for (int j=c+2;j<=15;j++) answer.m[j][0]=0;
  answer=chengfa(answer,quick_power(r,b-a+1));
  if (okabe) break;
  }
printf("%I64d",answer.m[1][1]);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll n,k,a,b,c;bool okabe;

ll reads()
{
ll x=0;char c=getchar();
while (c>'9'||c<'0') c=getchar();
while (c>='0'&&c<='9') x=x*10+c-48,c=getchar();
return x;
}

struct juzhen
{
ll m[18][18];
juzhen(){memset(m,0,sizeof(m));}
}answer,e;

juzhen chengfa(juzhen a,juzhen b)
{
juzhen answer;int i,j,k;
for (i=1;i<=c+1;i++) for (j=1;j<=c+1;j++) for (k=1;k<=c+1;k++) answer.m[i][j]=(answer.m[i][j]+a.m[i][k]*b.m[k][j]+mod)%mod;
return answer;
}

juzhen quick_power(juzhen a,ll b)
{
int i;
for (i=c+2;i<=16;i++) answer.m[i][1]=0;
for (;b;b>>=1,a=chengfa(a,a)) if (b&1) answer=chengfa(answer,a);
}

int main()
{
int i;
for (i=1;i<=15;i++)
  {
  e.m[i][i]=1;
  if (i) e.m[i][i-1]=1;
  if (i<15) e.m[i][i+1]=1;
  }
answer.m[1][1]=1;
n=reads(),k=reads();
for (i=1;i<=n;i++)
  {
  a=reads()+1,b=reads(),c=reads();
  if (k<b) b=k,okabe=1;
  quick_power(e,b-a+1);
  if (okabe) break;
  }
printf("%I64d",answer.m[1][1]);
}


#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
long long rd()
  {
  long long x = 0;
  char c = getchar();
  while (c > '9' || c < '0') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
  return x;
  }
const int P = 1e9 + 7;
struct Martix
  {
  int a[17][17];
  Martix()
    {
    memset(a, 0, sizeof a);
    }
  } ans;
long long n, K;
bool fg;
void Add(int &x, int y)
  {
  x += y;
  if (x >= P) x -= P;
  }
Martix mul(Martix A, Martix B, int C)
  {
  Martix re;
  for (int k = 0; k <= C; k ++)
    for (int i = 0; i <= C; i ++)
      for (int j = 0; j <= C; j ++)
        if (A.a[i][k] && B.a[k][j]) Add(re.a[i][j], 1ll * A.a[i][k] * B.a[k][j] % P);
  return re;
  }
void power(long long B, int C)
  {
  Martix e;
  for (int i = 0; i < 16; i ++)
    {
    e.a[i][i] = 1;
    if (i) e.a[i][i - 1] = 1;
    if (i + 1 < 16) e.a[i][i + 1] = 1;
    }
  for (int i = C + 1; i < 16; i ++) ans.a[i][0] = 0;
  for (; B; B >>= 1, e = mul(e, e, C)) if (B & 1) ans = mul(ans, e, C);
  }
int main()
  {
  n = rd(), K = rd();
  ans.a[0][0] = 1;
  for (int i = 0; i < n; i ++)
    {
    long long a = rd() + 1, b = rd(), c = rd();
    if (K < b) b = K, fg = 1;
    power(b - a + 1, c);
    if (fg) break;
    }
  printf("%d\n", ans.a[0][0]);
  return 0;
  }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll n,k,a,b,c;

struct juzhen
{
ll m[18][18];
void clearit()//chushihua
  {
  int i;
  memset(m,0,sizeof(m));
  for (i=1;i<=15;i++)
    {
    m[i][i]=1;
	if (i) m[i][i-1]=1;
	if (i<15) m[i][i+1]=1;
	}
  }
}r,kong;

juzhen chengfa(juzhen a,juzhen b)
{
int i,j,k;
juzhen answer;
memset(answer.m,0,sizeof(answer.m));
for (i=1;i<=c+1;i++) for (j=1;j<=c+1;j++) for (k=1;k<=c+1;k++) answer.m[i][j]=(answer.m[i][j]+a.m[i][k]*b.m[k][j]+mod)%mod;
return answer;
}

juzhen quick_power(juzhen a,ll b)
{
if (b==0) return kong;
else if (b==1) return a;
juzhen result=quick_power(a,b/2);
return b&1?chengfa(chengfa(result,result),a):chengfa(result,result);
}

int main()
{
r.clearit();int i;
for (i=1;i<=15;i++) kong.m[i][i]=1;
bool okabe=0;juzhen answer;
memset(answer.m,0,sizeof(answer.m));
scanf("%I64d%I64d",&n,&k);
answer.m[1][1]=1;
for (i=1;i<=n;i++)
  {
  scanf("%I64d%I64d%I64d",&a,&b,&c),a++;
  if (k<b) b=k,okabe=1;
  for (int j=c+2;j<=15;j++) answer.m[j][1]=0;
  answer=chengfa(answer,quick_power(r,b-a+1));
  if (okabe) break;
  }
printf("%I64d",answer.m[1][1]);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll n,k,a,b,c;bool okabe;

ll reads()
{
ll x=0;char c=getchar();
while (c>'9'||c<'0') c=getchar();
while (c>='0'&&c<='9') x=x*10+c-48,c=getchar();
return x;
}

struct juzhen
{
ll m[18][18];
juzhen(){memset(m,0,sizeof(m));}
}answer,e;

juzhen chengfa(juzhen a,juzhen b)
{
juzhen answer;int i,j,k;
for (i=1;i<=c+1;i++) for (j=1;j<=c+1;j++) for (k=1;k<=c+1;k++) answer.m[i][j]=(answer.m[i][j]+a.m[i][k]*b.m[k][j]+mod)%mod;
return answer;
}

juzhen quick_power(juzhen a,ll b)
{
int i;
for (i=c+2;i<=16;i++) answer.m[i][1]=0;
for (;b;b>>=1,a=chengfa(a,a)) if (b&1) answer=chengfa(answer,a);
}

int main()
{
int i;
for (i=1;i<=16;i++)
  {
  e.m[i][i]=1;
  if (i>1) e.m[i][i-1]=1;
  if (i<16) e.m[i][i+1]=1;
  }
answer.m[1][1]=1;
n=reads(),k=reads();
for (i=1;i<=n;i++)
  {
  a=reads()+1,b=reads(),c=reads();
  if (k<b) b=k,okabe=1;
  quick_power(e,b-a+1);
  if (okabe) break;
  }
printf("%I64d",answer.m[1][1]);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll n,k,a,b,c;

struct juzhen
{
ll m[18][18];
void clearit()//chushihua
  {
  int i;
  memset(m,0,sizeof(m));
  for (i=1;i<=15;i++)
    {
    m[i][i]=1;
	if (i) m[i][i-1]=1;
	if (i<15) m[i][i+1]=1;
	}
  }
}r,kong;

juzhen chengfa(juzhen a,juzhen b)
{
int i,j,k;
juzhen answer;
memset(answer.m,0,sizeof(answer.m));
for (i=1;i<=c+1;i++) for (j=1;j<=c+1;j++) for (k=1;k<=c+1;k++) answer.m[i][j]=(answer.m[i][j]+a.m[i][k]*b.m[k][j]+mod)%mod;
return answer;
}

juzhen quick_power(juzhen a,ll b)
{
if (b==0) return kong;
else if (b==1) return a;
juzhen result=quick_power(a,b/2);
return b&1?chengfa(chengfa(result,result),a):chengfa(result,result);
}

int main()
{
r.clearit();int i;
for (i=1;i<=15;i++) kong.m[i][i]=1;
bool okabe=0;juzhen answer;
memset(answer.m,0,sizeof(answer.m));
scanf("%I64d%I64d",&n,&k);
answer.m[1][1]=1;
for (i=1;i<=n;i++)
  {
  scanf("%I64d%I64d%I64d",&a,&b,&c),a++;
  if (k<b) b=k,okabe=1;
  for (int j=c+1;j<=15;j++) answer.m[j][1]=0;
  answer=chengfa(answer,quick_power(r,b-a+1));
  if (okabe) break;
  }
printf("%I64d",answer.m[1][1]);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll n,k,a,b,c;
bool okabe;

ll reads()
  {
  ll x=0;
  char c=getchar();
  while (c>'9'||c<'0') c=getchar();
  while (c>='0'&&c<='9') x=x*10+c-48,c=getchar();
  return x;
  }

struct juzhen
  {
  ll m[18][18];
  juzhen()
    {
    memset(m,0,sizeof(m));
    }
  } answer,e;

juzhen chengfa(juzhen a,juzhen b)
  {
  juzhen answer;
  int i,j,k;
  for (i=1; i<=c+1; i++) for (j=1; j<=c+1; j++) for (k=1; k<=c+1; k++) answer.m[i][j]=(answer.m[i][j]+a.m[i][k]*b.m[k][j]+mod)%mod;
  return answer;
  }

juzhen quick_power(juzhen a,ll b)
  {
  int i;
  for (i=c+2; i<=16; i++) answer.m[i][1]=0;
  for (; b; b>>=1,a=chengfa(a,a)) if (b&1) answer=chengfa(answer,a);
  }

int main()
  {
  int i;
  for (i=1; i<=15; i++)
    {
    e.m[i][i]=1;
    if (i) e.m[i][i-1]=1;
    if (i<16) e.m[i][i+1]=1;
    }
  answer.m[1][1]=1;
  n=reads(),k=reads();
  for (i=1; i<=n; i++)
    {
    a=reads()+1,b=reads(),c=reads();
    if (k<b) b=k,okabe=1;
    quick_power(e,b-a+1);
    if (okabe) break;
    }
  printf("%I64d",answer.m[1][1]);
  }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll n,k,a,b,c;

struct juzhen
{
ll m[18][18];
void clearit()//chushihua
  {
  int i;
  memset(m,0,sizeof(m));
  for (i=1;i<=15;i++)
    {
    m[i][i]=1;
	if (i) m[i][i-1]=1;
	if (i<15) m[i][i+1]=1;
	}
  }
}r,kong;

juzhen chengfa(juzhen a,juzhen b)
{
int i,j,k;
juzhen answer;
memset(answer.m,0,sizeof(answer.m));
for (i=1;i<=c+1;i++) for (j=1;j<=c+1;j++) for (k=1;k<=c+1;k++) answer.m[i][j]=(answer.m[i][j]+a.m[i][k]*b.m[k][j]+mod)%mod;
return answer;
}

juzhen quick_power(juzhen a,ll b)
{
if (b==0) return kong;
else if (b==1) return a;
juzhen result=quick_power(a,b/2);
return b&1?chengfa(chengfa(result,result),a):chengfa(result,result);
}

int main()
{
r.clearit();int i;
for (i=1;i<=15;i++) kong.m[i][i]=1;
bool okabe=0;juzhen answer;
memset(answer.m,0,sizeof(answer.m));
scanf("%I64d%I64d",&n,&k);
answer.m[1][1]=1;
for (i=1;i<=n;i++)
  {
  scanf("%I64d%I64d%I64d",&a,&b,&c),a++;
  if (k<b) b=k,okabe=1;
  for (int j=c+1;j<=15;j++) answer.m[j][0]=0;
  answer=chengfa(answer,quick_power(r,b-a+1));
  if (okabe) break;
  }
printf("%I64d",answer.m[1][1]);
}


#include <iostream>
#include <cassert>

using namespace std;

#define ll long long
int const nmax = 16;
int const modulo = 1000000007;

struct Matrix{
  int n , m;
  int v[5 + nmax][5 + nmax];
  void clearmat(){
    for(int i = 0 ; i <= n ;i++){
      for(int j = 0 ; j <= m ;j++){
        v[i][j] = 0;
      }
    }
  }
  Matrix operator * (Matrix const a) const{
    Matrix result;
    result.n = n;
    result.m = a.m;
    result.clearmat();
    for(int i = 1 ; i <= n ;i++){
      for(int j = 1 ; j <= a.m ;j++){
        for(int h = 1 ; h <= m ;h++){
          result.v[i][j] += ((1LL * v[i][h] * a.v[h][j]) % modulo);
          result.v[i][j] %= modulo;
        }
      }
    }
    return result;
  }
};
Matrix lgpow(Matrix a , ll b){
  if(b == 0){
    Matrix neutral;
    neutral.clearmat();
    neutral.n = neutral.m = a.m;
    for(int i = 1 ; i <= neutral.n ;i++){
      neutral.v[i][i] = 1;
    }
    return neutral;
  } else if(b == 1)
    return a;
  else{
    Matrix result = lgpow(a , b / 2);
    if(b % 2 == 0)
      return result * result;
    else
      return result * result * a;
  }
}

Matrix lim(int val){
  Matrix result;
  result.n = result.m = nmax;
  result.clearmat();
  for(int i = 1;i <= val; i++){
    result.v[i - 1][i] = 1;
    result.v[i][i] = 1;
    result.v[i + 1][i] = 1;
  }
  return result;
}

int main()
{
  Matrix init;
  init.n = init.m = nmax;
  init.clearmat();
  init.v[1][1] = 1;///pentru punctul 0
  int n;
  ll k;
  cin >> n >> k;
  int last = 20;
  ll step = 0;
  for(int i = 1;i <= n; i++){
    ll a, b;
    int c;
    cin >> a >> b >> c;
    if(n == 35)
      cout << a << " " << b << " " << c << '\n';

    c++;
    if(i == n)
      b = k + 1;
    if(1 < i) {
      init = init * lim(min(c, last));
      step++;
    }
    init = init * lgpow(lim(c), b - a - 1);
    step += (b - a - 1);
    last = c;
  }
  assert(step == k);
  cout << init.v[1][1];
  return 0;
}
/*
1 10
0 10 3
2135 3410 3355 2046 0 0 0 0 0 0 0 0 0 0 0 0
2135
*/


#include <iostream>
#include <cassert>

using namespace std;

#define ll long long
int const nmax = 16;
int const modulo = 1000000007;

struct Matrix{
  int n , m;
  int v[5 + nmax][5 + nmax];
  void clearmat(){
    for(int i = 0 ; i <= n ;i++){
      for(int j = 0 ; j <= m ;j++){
        v[i][j] = 0;
      }
    }
  }
  Matrix operator * (Matrix const a) const{
    Matrix result;
    result.n = n;
    result.m = a.m;
    result.clearmat();
    for(int i = 1 ; i <= n ;i++){
      for(int j = 1 ; j <= a.m ;j++){
        for(int h = 1 ; h <= m ;h++){
          result.v[i][j] += ((1LL * v[i][h] * a.v[h][j]) % modulo);
          result.v[i][j] %= modulo;
        }
      }
    }
    return result;
  }
};
Matrix lgpow(Matrix a , ll b){
  if(b == 0){
    Matrix neutral;
    neutral.clearmat();
    neutral.n = neutral.m = a.m;
    for(int i = 1 ; i <= neutral.n ;i++){
      neutral.v[i][i] = 1;
    }
    return neutral;
  } else if(b == 1)
    return a;
  else{
    Matrix result = lgpow(a , b / 2);
    if(b % 2 == 0)
      return result * result;
    else
      return result * result * a;
  }
}

Matrix lim(int val){
  Matrix result;
  result.n = result.m = nmax;
  result.clearmat();
  for(int i = 1;i <= val; i++){
    result.v[i - 1][i] = 1;
    result.v[i][i] = 1;
    result.v[i + 1][i] = 1;
  }
  return result;
}

int main()
{
  Matrix init;
  init.n = init.m = nmax;
  init.clearmat();
  init.v[1][1] = 1;///pentru punctul 0
  int n;
  ll k;
  cin >> n >> k;
  int last = 20;
  ll step = 0;
  for(int i = 1;i <= n; i++){
    ll a, b;
    int c;
    cin >> a >> b >> c;
    if(n == 35 && 10 < i)
      cout << a << " " << b << " " << c << '\n';

    c++;
    if(i == n)
      b = k + 1;
    if(1 < i) {
      init = init * lim(min(c, last));
      step++;
    }
    init = init * lgpow(lim(c), b - a - 1);
    step += (b - a - 1);
    last = c;
  }
  assert(step == k);
  cout << init.v[1][1];
  return 0;
}
/*
1 10
0 10 3
2135 3410 3355 2046 0 0 0 0 0 0 0 0 0 0 0 0
2135
*/

/*
35 999999999999999992
0 603321843709333562 6
603321843709333562 883827292220408505 0
883827292220408505 981460098737241157 11
981460098737241157 998460573617180215 5
998460573617180215 998882290717571902 8
998882290717571902 999587602514737784 11
999587602514737784 999589324058448040 7
999589324058448040 999834434910911178 13
999834434910911178 999983917426978005 7
999983917426978005 999992168837566183 13
999992168837566183 999997394762503307 9
999997394762503307 999997649100207969 13
*/


#include <iostream>
#include <cassert>
#include <vector>

using namespace std;

using ll = long long;
int const nmax = 16;
int const modulo = 1000000007;

class Matrix{
//indexed from 1
private:
  int n, m;
  using ll = long long;
public:
  vector<vector<int>> mat;
  Matrix(int n, int m){
    this->n = n;
    this->m = m;

    mat.resize(1 + n);
    for(int i = 1;i <= n; i++)
      mat[i].resize(1 + m);
  }
  Matrix operator * (Matrix const &a) const{
    assert(m == a.n);
    Matrix result(n, a.m);
    for(int i = 1;i <= n; i++)
      for(int j = 1;j <= a.m; j++)
        for(int h = 1; h <= m; h++)
          result.mat[i][j] = (result.mat[i][j] + 1LL * mat[i][h] * a.mat[h][j]) % modulo;
    return result;
  }

  Matrix lgpow(Matrix a, ll b){
    if(b == 0){
      Matrix result(a.n, a.m);
      for(int i = 1;i <= a.n; i++)
        result.mat[i][i] = 1;
      return result;
    } else if(b == 1)
      return a;
    else {
      Matrix result = lgpow(a, b / 2);
      if(b % 2 == 0)
        return result * result;
      else
        return result * result * a;
    }
  }
  Matrix operator ^ (ll b){
    return lgpow(*this, b);
  }
};

Matrix lim(int val){
  Matrix result(nmax, nmax);
  for(int i = 1;i <= val; i++){
    if(1 <= i - 1)
      result.mat[i - 1][i] = 1;
    result.mat[i][i] = 1;
    if(i + 1 <= nmax)
      result.mat[i + 1][i] = 1;
  }
  return result;
}

int main()
{
  Matrix init(nmax, nmax);
  init.mat[1][1] = 1;///pentru punctul 0
  int n;
  ll k;
  cin >> n >> k;
  int last = 20;
  ll step = 0;
  for(int i = 1;i <= n; i++){
    ll a, b;
    int c;
    cin >> a >> b >> c;
    c++;
    if(i == n)
      b = k + 1;
    if(1 < i) {
      init = init * lim(min(c, last));
      step++;
    }
    init = init * (lim(c) ^ (b - a - 1));
    step += (b - a - 1);
    last = c;
  }
  assert(step == k);
  cout << init.mat[1][1];
  return 0;
}


#include <iostream>
#include <cassert>

using namespace std;

#define ll long long
int const nmax = 16;
int const modulo = 1000000007;

struct Matrix{
  int n , m;
  int v[5 + nmax][5 + nmax];
  void clearmat(){
    for(int i = 0 ; i <= n ;i++){
      for(int j = 0 ; j <= m ;j++){
        v[i][j] = 0;
      }
    }
  }
  Matrix operator * (Matrix const a) const{
    Matrix result;
    result.n = n;
    result.m = a.m;
    result.clearmat();
    for(int i = 1 ; i <= n ;i++){
      for(int j = 1 ; j <= a.m ;j++){
        for(int h = 1 ; h <= m ;h++){
          result.v[i][j] += ((1LL * v[i][h] * a.v[h][j]) % modulo);
          result.v[i][j] %= modulo;
        }
      }
    }
    return result;
  }
};
Matrix lgpow(Matrix a , ll b){
  if(b == 0){
    Matrix neutral;
    neutral.clearmat();
    neutral.n = neutral.m = a.m;
    for(int i = 1 ; i <= neutral.n ;i++){
      neutral.v[i][i] = 1;
    }
    return neutral;
  } else if(b == 1)
    return a;
  else{
    Matrix result = lgpow(a , b / 2);
    if(b % 2 == 0)
      return result * result;
    else
      return result * result * a;
  }
}

Matrix lim(int val){
  Matrix result;
  result.n = result.m = nmax;
  result.clearmat();
  for(int i = 1;i <= val; i++){
    result.v[i - 1][i] = 1;
    result.v[i][i] = 1;
    result.v[i + 1][i] = 1;
  }
  return result;
}

int main()
{
  Matrix init;
  init.n = init.m = nmax;
  init.clearmat();
  init.v[1][1] = 1;///pentru punctul 0
  int n;
  ll k;
  cin >> n >> k;
  int last = 20;
  ll step = 0;
  for(int i = 1;i <= n; i++){
    ll a, b;
    int c;
    cin >> a >> b >> c;
    if(n == 35 && 20 < i)
      cout << a << " " << b << " " << c << '\n';

    c++;
    if(i == n)
      b = k + 1;
    if(1 < i) {
      init = init * lim(min(c, last));
      step++;
    }
    init = init * lgpow(lim(c), b - a - 1);
    step += (b - a - 1);
    last = c;
  }
  assert(step == k);
  cout << init.v[1][1];
  return 0;
}
/*
1 10
0 10 3
2135 3410 3355 2046 0 0 0 0 0 0 0 0 0 0 0 0
2135
*/

/*
35 999999999999999992
0 603321843709333562 6
603321843709333562 883827292220408505 0
883827292220408505 981460098737241157 11
981460098737241157 998460573617180215 5
998460573617180215 998882290717571902 8
998882290717571902 999587602514737784 11
999587602514737784 999589324058448040 7
999589324058448040 999834434910911178 13
999834434910911178 999983917426978005 7
999983917426978005 999992168837566183 13
999992168837566183 999997394762503307 9
999997394762503307 999997649100207969 13
999997649100207969 999999269213782217 4
999999269213782217 999999280908086336 6
999999280908086336 999999292080131902 1
999999292080131902 999999774324210940 5
999999774324210940 999999841035389886 15
999999841035389886 999999928693004538 9
999999928693004538 999999975144123715 0
999999975144123715 999999979245039323 7
999999979245039323 999999997285703699 11
999999997285703699 999999999945937587 6
*/


#include <iostream>
#include <cassert>

using namespace std;

#define ll long long
int const nmax = 16;
int const modulo = 1000000007;

struct Matrix{
  int n , m;
  int v[5 + nmax][5 + nmax];
  void clearmat(){
    for(int i = 0 ; i <= n ;i++){
      for(int j = 0 ; j <= m ;j++){
        v[i][j] = 0;
      }
    }
  }
  Matrix operator * (Matrix const a) const{
    Matrix result;
    result.n = n;
    result.m = a.m;
    result.clearmat();
    for(int i = 1 ; i <= n ;i++){
      for(int j = 1 ; j <= a.m ;j++){
        for(int h = 1 ; h <= m ;h++){
          result.v[i][j] += ((1LL * v[i][h] * a.v[h][j]) % modulo);
          result.v[i][j] %= modulo;
        }
      }
    }
    return result;
  }
};
Matrix lgpow(Matrix a , ll b){
  if(b == 0){
    Matrix neutral;
    neutral.clearmat();
    neutral.n = neutral.m = a.m;
    for(int i = 1 ; i <= neutral.n ;i++){
      neutral.v[i][i] = 1;
    }
    return neutral;
  } else if(b == 1)
    return a;
  else{
    Matrix result = lgpow(a , b / 2);
    if(b % 2 == 0)
      return result * result;
    else
      return result * result * a;
  }
}

Matrix lim(int val){
  Matrix result;
  result.n = result.m = nmax;
  result.clearmat();
  for(int i = 1;i <= val; i++){
    result.v[i - 1][i] = 1;
    result.v[i][i] = 1;
    result.v[i + 1][i] = 1;
  }
  return result;
}

int main()
{
  Matrix init;
  init.n = init.m = nmax;
  init.clearmat();
  init.v[1][1] = 1;///pentru punctul 0
  int n;
  ll k;
  cin >> n >> k;
  int last = 20;
  ll step = 0;
  for(int i = 1;i <= n; i++){
    ll a, b;
    int c;
    cin >> a >> b >> c;
    if(n == 35 && 30 < i)
      cout << a << " " << b << " " << c << '\n';

    c++;
    if(i == n)
      b = k + 1;
    if(1 < i) {
      init = init * lim(min(c, last));
      step++;
    }
    init = init * lgpow(lim(c), b - a - 1);
    step += (b - a - 1);
    last = c;
  }
  assert(step == k);
  cout << init.v[1][1];
  return 0;
}
/*
1 10
0 10 3
2135 3410 3355 2046 0 0 0 0 0 0 0 0 0 0 0 0
2135
*/

/*
35 999999999999999992
0 603321843709333562 6
603321843709333562 883827292220408505 0
883827292220408505 981460098737241157 11
981460098737241157 998460573617180215 5
998460573617180215 998882290717571902 8
998882290717571902 999587602514737784 11
999587602514737784 999589324058448040 7
999589324058448040 999834434910911178 13
999834434910911178 999983917426978005 7
999983917426978005 999992168837566183 13
999992168837566183 999997394762503307 9
999997394762503307 999997649100207969 13
999997649100207969 999999269213782217 4
999999269213782217 999999280908086336 6
999999280908086336 999999292080131902 1
999999292080131902 999999774324210940 5
999999774324210940 999999841035389886 15
999999841035389886 999999928693004538 9
999999928693004538 999999975144123715 0
999999975144123715 999999979245039323 7
999999979245039323 999999997285703699 11
999999997285703699 999999999945937587 6
999999999945937587 999999999990775540 8
999999999990775540 999999999996159069 3
999999999996159069 999999999996977083 7
999999999996977083 999999999999898042 14
999999999999898042 999999999999967392 9
999999999999967392 999999999999987302 12
999999999999987302 999999999999998936 5
999999999999998936 999999999999999228 3
999999999999999228 999999999999999757 5
999999999999999757 999999999999999813 0
*/


#include <iostream>
#include <cassert>

using namespace std;

#define ll long long
int const nmax = 16;
int const modulo = 1000000007;

struct Matrix{
  int n , m;
  int v[5 + nmax][5 + nmax];
  void clearmat(){
    for(int i = 0 ; i <= nmax ;i++){
      for(int j = 0 ; j <= nmax ;j++){
        v[i][j] = 0;
      }
    }
  }
  Matrix operator * (Matrix const a) const{
    Matrix result;
    result.n = n;
    result.m = a.m;
    result.clearmat();
    for(int i = 1 ; i <= n ;i++){
      for(int j = 1 ; j <= a.m ;j++){
        for(int h = 1 ; h <= m ;h++){
          result.v[i][j] += ((1LL * v[i][h] * a.v[h][j]) % modulo);
          result.v[i][j] %= modulo;
        }
      }
    }
    return result;
  }
};
Matrix lgpow(Matrix a , ll b){
  if(b == 0){
    Matrix neutral;
    neutral.clearmat();
    neutral.n = neutral.m = a.m;
    for(int i = 1 ; i <= neutral.n ;i++){
      neutral.v[i][i] = 1;
    }
    return neutral;
  } else if(b == 1)
    return a;
  else{
    Matrix result = lgpow(a , b / 2);
    if(b % 2 == 0)
      return result * result;
    else
      return result * result * a;
  }
}

Matrix lim(int val){
  Matrix result;
  result.n = result.m = nmax;
  result.clearmat();
  for(int i = 1;i <= val; i++){
    result.v[i - 1][i] = 1;
    result.v[i][i] = 1;
    result.v[i + 1][i] = 1;
  }
  return result;
}

int main()
{
  Matrix init;
  init.n = init.m = nmax;
  init.clearmat();
  init.v[1][1] = 1;///pentru punctul 0
  int n;
  ll k;
  cin >> n >> k;
  int last = 20;
  ll step = 0;
  for(int i = 1;i <= n; i++){
    ll a, b;
    int c;
    cin >> a >> b >> c;
    c++;
    if(i == n)
      b = k + 1;
    if(1 < i) {
      init = init * lim(min(c, last));
      step++;
    }
    init = init * lgpow(lim(c), b - a - 1);
    step += (b - a - 1);
    last = c;
  }
  assert(step == k);
  cout << init.v[1][1];
  return 0;
}
/*
1 10
0 10 3
2135 3410 3355 2046 0 0 0 0 0 0 0 0 0 0 0 0
2135
*/

/*
35 999999999999999992
0 603321843709333562 6
603321843709333562 883827292220408505 0
883827292220408505 981460098737241157 11
981460098737241157 998460573617180215 5
998460573617180215 998882290717571902 8
998882290717571902 999587602514737784 11
999587602514737784 999589324058448040 7
999589324058448040 999834434910911178 13
999834434910911178 999983917426978005 7
999983917426978005 999992168837566183 13
999992168837566183 999997394762503307 9
999997394762503307 999997649100207969 13
999997649100207969 999999269213782217 4
999999269213782217 999999280908086336 6
999999280908086336 999999292080131902 1
999999292080131902 999999774324210940 5
999999774324210940 999999841035389886 15
999999841035389886 999999928693004538 9
999999928693004538 999999975144123715 0
999999975144123715 999999979245039323 7
999999979245039323 999999997285703699 11
999999997285703699 999999999945937587 6
999999999945937587 999999999990775540 8
999999999990775540 999999999996159069 3
999999999996159069 999999999996977083 7
999999999996977083 999999999999898042 14
999999999999898042 999999999999967392 9
999999999999967392 999999999999987302 12
999999999999987302 999999999999998936 5
999999999999998936 999999999999999228 3
999999999999999228 999999999999999757 5
999999999999999757 999999999999999813 0
999999999999999813 999999999999999979 6
999999999999999979 999999999999999992 4
999999999999999992 1000000000000000000 12
*/


#include <iostream>
#include <cassert>

using namespace std;

#define ll long long
int const nmax = 16;
int const modulo = 1000000007;

struct Matrix{
  int n , m;
  int v[5 + nmax][5 + nmax];
  void clearmat(){
    for(int i = 0 ; i <= n ;i++){
      for(int j = 0 ; j <= m ;j++){
        v[i][j] = 0;
      }
    }
  }
  Matrix operator * (Matrix const a) const{
    Matrix result;
    result.n = n;
    result.m = a.m;
    result.clearmat();
    for(int i = 1 ; i <= n ;i++){
      for(int j = 1 ; j <= a.m ;j++){
        for(int h = 1 ; h <= m ;h++){
          result.v[i][j] += ((1LL * v[i][h] * a.v[h][j]) % modulo);
          result.v[i][j] %= modulo;
        }
      }
    }
    return result;
  }
};
Matrix lgpow(Matrix a , ll b){
  if(b == 0){
    Matrix neutral;
    neutral.clearmat();
    neutral.n = neutral.m = a.m;
    for(int i = 1 ; i <= neutral.n ;i++){
      neutral.v[i][i] = 1;
    }
    return neutral;
  } else if(b == 1)
    return a;
  else{
    Matrix result = lgpow(a , b / 2);
    if(b % 2 == 0)
      return result * result;
    else
      return result * result * a;
  }
}

Matrix lim(int val){
  Matrix result;
  result.n = result.m = nmax;
  result.clearmat();
  for(int i = 1;i <= val; i++){
    result.v[i - 1][i] = 1;
    result.v[i][i] = 1;
    result.v[i + 1][i] = 1;
  }
  return result;
}

int main()
{
  Matrix init;
  init.n = init.m = nmax;
  init.clearmat();
  init.v[1][1] = 1;///pentru punctul 0
  int n;
  ll k;
  cin >> n >> k;

  int last = 20;
  ll step = 0;
  for(int i = 1;i <= n; i++){
    ll a, b;
    int c;
    cin >> a >> b >> c;
    c++;
    if(i == n)
      b = k + 1;
    if(1 < i) {
      init = init * lim(min(c, last));
      step++;
    }

    /*
    for(int i = 1; i <= nmax; i++)
      cout << init.v[1][i] << " ";
    cout << '\n';
    */

    init = init * lgpow(lim(c), b - a - 1);
    /*
    for(int i = 1; i <= nmax; i++)
      cout << init.v[1][i] << " ";
    cout << '\n';
    */

    step += (b - a - 1);
    last = c;
  }
  assert(step == k);
  cout << init.v[1][1];
  return 0;
}
/*
1 1
0 2 3
2
*/


#include <iostream>

using namespace std;

#define ll long long
int const nmax = 16;
int const modulo = 1000000007;

struct Matrix{
  int n , m;
  int v[5 + nmax][5 + nmax];
  void clearmat(){
    for(int i = 1 ; i <= n ;i++){
      for(int j = 1 ; j <= m ;j++){
        v[i][j] = 0;
      }
    }
  }
  Matrix operator * (Matrix const a) const{
    Matrix result;
    result.n = n;
    result.m = a.m;
    result.clearmat();
    for(int i = 1 ; i <= n ;i++){
      for(int j = 1 ; j <= a.m ;j++){
        for(int h = 1 ; h <= m ;h++){
          result.v[i][j] += ((1LL * v[i][h] * a.v[h][j]) % modulo);
          result.v[i][j] %= modulo;
        }
      }
    }
    return result;
  }
};
Matrix lgpow(Matrix a , ll b){
  if(b == 0){
    Matrix neutral;
    neutral.n = neutral.m = a.m;
    for(int i = 1 ; i <= neutral.n ;i++){
      neutral.v[i][i] = 1;
    }
    return neutral;
  } else if(b == 1)
    return a;
  else{
    Matrix result = lgpow(a , b / 2);
    if(b % 2 == 0)
      return result * result;
    else
      return result * result * a;
  }
}

Matrix lim(int val){
  Matrix result;
  result.n = result.m = nmax;
  result.clearmat();
  for(int i = 1;i <= val; i++){
    result.v[i - 1][i] = 1;
    result.v[i][i] = 1;
    result.v[i + 1][i] = 1;
  }
  return result;
}

int main()
{
  Matrix init;
  init.n = init.m = nmax;
  init.clearmat();
  init.v[1][1] = 1;///pentru punctul 0
  int n;
  ll k;
  cin >> n >> k;

  int last = 16;
  for(int i = 1;i <= n; i++){
    ll a, b;
    int c;
    cin >> a >> b >> c;
    c++;
    if(i == n)
      b = k + 1;
    if(1 < i)
      init = init * lim(min(c, last));
    init = init * lgpow(lim(c), b - a - 1);
    last = c;
  }
  ll result = 0;
  cout << init.v[1][1];
  return 0;
}


#include <iostream>
#include <cassert>

using namespace std;

#define ll long long
int const nmax = 16;
int const modulo = 1000000007;

struct Matrix{
  int n , m;
  int v[5 + nmax][5 + nmax];
  void clearmat(){
    for(int i = 0 ; i <= n ;i++){
      for(int j = 0 ; j <= m ;j++){
        v[i][j] = 0;
      }
    }
  }
  Matrix operator * (Matrix const a) const{
    Matrix result;
    result.n = n;
    result.m = a.m;
    result.clearmat();
    for(int i = 1 ; i <= n ;i++){
      for(int j = 1 ; j <= a.m ;j++){
        for(int h = 1 ; h <= m ;h++){
          result.v[i][j] += ((1LL * v[i][h] * a.v[h][j]) % modulo);
          result.v[i][j] %= modulo;
        }
      }
    }
    return result;
  }
};
Matrix lgpow(Matrix a , ll b){
  if(b == 0){
    Matrix neutral;
    neutral.n = neutral.m = a.m;
    for(int i = 1 ; i <= neutral.n ;i++){
      neutral.v[i][i] = 1;
    }
    return neutral;
  } else if(b == 1)
    return a;
  else{
    Matrix result = lgpow(a , b / 2);
    if(b % 2 == 0)
      return result * result;
    else
      return result * result * a;
  }
}

Matrix lim(int val){
  Matrix result;
  result.n = result.m = nmax;
  result.clearmat();
  for(int i = 1;i <= val; i++){
    result.v[i - 1][i] = 1;
    result.v[i][i] = 1;
    result.v[i + 1][i] = 1;
  }
  return result;
}

int main()
{
  Matrix init;
  init.n = init.m = nmax;
  init.clearmat();
  init.v[1][1] = 1;///pentru punctul 0
  int n;
  ll k;
  cin >> n >> k;

  int last = 20;
  ll step = 0;
  for(int i = 1;i <= n; i++){
    ll a, b;
    int c;
    cin >> a >> b >> c;
    c++;
    if(i == n)
      b = k + 1;
    if(1 < i) {
      init = init * lim(min(c, last));
      step++;
    }

    /*
    for(int i = 1; i <= nmax; i++)
      cout << init.v[1][i] << " ";
    cout << '\n';
    */

    init = init * lgpow(lim(c), b - a - 1);
    /*
    for(int i = 1; i <= nmax; i++)
      cout << init.v[1][i] << " ";
    cout << '\n';
    */

    step += (b - a - 1);
    last = c;
  }
  assert(step == k);
  cout << init.v[1][1];
  return 0;
}
/*
1 1
0 2 3
2
*/


#include <bits/stdc++.h>

using namespace std;

const long long M = 1e9 + 7;

typedef vector<vector<long long>> Matrix;

Matrix operator *(const Matrix &a, const Matrix &b) {
    assert(a[0].size() == b.size());
    Matrix res(a.size(), vector<long long>(b.size(), 0));
    for(int i = 0; i < a.size(); i++) {
        for(int j = 0; j < b[0].size(); j++) {
            for(int k = 0; k < b.size(); k++) {
                res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % M;
            }
        }
    }
    return res;
}

void operator *=(Matrix &a, const Matrix &b) {
    a = a * b;
}

Matrix binPow(Matrix a, long long b) {
    Matrix res = a;
    b--;
    while(b > 0) {
        if(b & 1) res *= a;
        a *= a;
        b /= 2;
    }
    return res;
}

Matrix makeMatrix(int coordinate) {
    Matrix can(16, vector<long long>(16, 0));
    for(int i = 0; i < 16; i++) {
        if(i - 1 >= 0 && i != coordinate) can[i][i - 1] = 1;
        if(i + 1 < 16 && i != coordinate) can[i][i + 1] = 1;
        can[i][i] = 1;
    }
    return can;
}

int main() {
    int n;
    long long k;

    cin >> n >> k;
    Matrix res(1, vector<long long>(16, 0));
    res[0][0] = 1;

    for(int i = 1; i <= n; i++) {
        long long a, b;
        int c;
        cin >> a >> b >> c;
        if(b <= k) {
            res *= binPow(makeMatrix(c), b - a);
            if(i == n && k != b) {
                res *= binPow(makeMatrix(-1), k - b);
            }
        }
        else {
            if(a < k && k <= b) {
                res *= binPow(makeMatrix(c), k - a);
            }
        }
    }
    cout << res[0][0];
}


#include <bits/stdc++.h>

using namespace std;

const long long M = 1e9 + 7;

typedef vector<vector<long long>> Matrix;

Matrix operator *(const Matrix &a, const Matrix &b) {
    assert(a[0].size() == b.size());
    Matrix res(a.size(), vector<long long>(b.size(), 0));
    for(int i = 0; i < a.size(); i++) {
        for(int j = 0; j < b[0].size(); j++) {
            for(int k = 0; k < b.size(); k++) {
                res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % M;
            }
        }
    }
    return res;
}

void operator *=(Matrix &a, const Matrix &b) {
    a = a * b;
}

Matrix binPow(Matrix a, long long b) {
    Matrix res = a;
    b--;
    while(b > 0) {
        if(b & 1) res *= a;
        a *= a;
        b /= 2;
    }
    return res;
}

Matrix makeMatrix(int coordinate) {
    Matrix can(16, vector<long long>(16, 0));
    for(int i = 0; i < 16; i++) {
        if(i - 1 >= 0 && i != coordinate) can[i][i - 1] = 1;
        if(i + 1 < 16 && i != coordinate) can[i][i + 1] = 1;
        can[i][i] = 1;
    }
    return can;
}

int main() {
    int n;
    long long k;

    cin >> n >> k;
    Matrix res(1, vector<long long>(16, 0));
    res[0][0] = 1;

    for(int i = 1; i <= n; i++) {
        long long a, b;
        int c;
        cin >> a >> b >> c;
        if(i == n) b = k;
        if(a < b) {
            res *= binPow(makeMatrix(c), b - a);
        }
    }
    cout << res[0][0];
}


#include <bits/stdc++.h>

using namespace std;

const long long M = 1e9 + 7;

typedef vector<vector<long long>> Matrix;

Matrix operator *(const Matrix &a, const Matrix &b) {
    assert(a[0].size() == b.size());
    Matrix res(a.size(), vector<long long>(b.size(), 0));
    for(int i = 0; i < a.size(); i++) {
        for(int j = 0; j < b[0].size(); j++) {
            for(int k = 0; k < b.size(); k++) {
                res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % M;
            }
        }
    }
    return res;
}

void operator *=(Matrix &a, const Matrix &b) {
    a = a * b;
}

Matrix binPow(Matrix a, long long b) {
    assert(b > 0);
    Matrix res = a;
    b--;
    while(b > 0) {
        if(b & 1) res *= a;
        a *= a;
        b /= 2;
    }
    return res;
}

Matrix makeMatrix(int coordinate) {
    Matrix can(32, vector<long long>(32, 0));
    for(int i = 0; i < 32; i++) {
        if(i - 1 >= 0 && i != coordinate) can[i][i - 1] = 1;
        if(i + 1 < 16 && i != coordinate) can[i][i + 1] = 1;
        can[i][i] = 1;
    }
    return can;
}

int main() {
    int n;
    long long k;

    cin >> n >> k;
    Matrix res(1, vector<long long>(32, 0));
    res[0][0] = 1;

    for(int i = 1; i <= n; i++) {
        long long a, b;
        int c;
        cin >> a >> b >> c;
        if(i == n) b = k;
        if(a < b) {
            res *= binPow(makeMatrix(c), b - a);
        }
    }
    cout << res[0][0];
}


#include <bits/stdc++.h>

using namespace std;

const long long M = 1e9 + 7;

typedef vector<vector<long long>> Matrix;

Matrix operator *(const Matrix &a, const Matrix &b) {
    assert(a[0].size() == b.size());
    Matrix res(a.size(), vector<long long>(b.size(), 0));
    for(int i = 0; i < a.size(); i++) {
        for(int j = 0; j < b[0].size(); j++) {
            for(int k = 0; k < b.size(); k++) {
                res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % M;
            }
        }
    }
    return res;
}

void operator *=(Matrix &a, const Matrix &b) {
    a = a * b;
}

Matrix binPow(Matrix a, long long b) {
    assert(b > 0);
    Matrix res = a;
    b--;
    while(b > 0) {
        if(b & 1) res *= a;
        a *= a;
        b /= 2;
    }
    return res;
}

Matrix makeMatrix(int coordinate) {
    Matrix can(coordinate + 1, vector<long long>(coordinate + 1, 0));
    for(int i = 0; i <= coordinate; i++) {
        if(i - 1 >= 0) can[i][i - 1] = 1;
        if(i + 1 <= coordinate) can[i][i + 1] = 1;
        can[i][i] = 1;
    }
    return can;
}

int main() {
    int n;
    long long k;

    cin >> n >> k;
    Matrix res(1, vector<long long>(1, 1));
    for(int i = 1; i <= n; i++) {
        long long a, b;
        int c;
        cin >> a >> b >> c;
        while(res[0].size() < c + 1) res[0].push_back(0);
        while(res[0].size() > c + 1) res[0].pop_back();

        if(i == n) b = k;
        if(a < b) res *= binPow(makeMatrix(c), b - a);
    }
    cout << res[0][0];
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // yamin

const int maxn = 110;
ll a[maxn], b[maxn], c[maxn];

struct Matrix {
	int sz;
	vvi a;
	Matrix() {
		sz = 0;
	}
	Matrix(int sz) {
		this->sz = sz;
		a.assign(sz, vi(sz, 0));
	}
	friend Matrix Mul(const Matrix& p, const Matrix& q) {
		int sz = p.sz;
		Matrix r(sz);
		for(int k = 0; k < sz; ++k) {
			for(int i = 0; i < sz; ++i) {
				for(int j = 0; j < sz; ++j) {
					r.a[i][j] = modAdd(r.a[i][j], modMul(p.a[i][k], q.a[k][j]));
				}
			}
		}
		return r;
	}
};

Matrix Gen(int sz) {
	Matrix r(sz);
	for(int j = 0; j < sz; ++j) {
		if(j - 1 >= 0) r.a[j-1][j] = 1;
		r.a[j][j] = 1;
		if(j + 1 < sz) r.a[j+1][j] = 1;
	}
	return r;
}

Matrix unitaryMatrix(int sz) {
	Matrix r(sz);
	for(int i = 0; i < sz; ++i) r.a[i][i] = 1;
	return r;
}

Matrix Pow(Matrix b, ll p) {
	Matrix r = unitaryMatrix(b.sz);
	while(p > 0) {
		if(p&1LL) r = Mul(b, r);
		b = Mul(b, b);
		p >>= 1LL;
	}
	return r;
}

int main() {
	int n, k; cin >> n >> k;
	for(int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i] >> c[i];
		++c[i];
	}
	b[n-1] = k;
	vi lol; lol.PB(1);
	for(int i = 0; i < n; ++i) {
		lol.resize(c[i]);
		vi fuck = lol;
		dbg(Gen(c[i]).a, b[i] - a[i]);
		Matrix r = Pow(Gen(c[i]), b[i] - a[i]);
		for(int j = 0; j < c[i]; ++j) {
			dbg(j);
			int temp = 0;
			for(int k = 0; k < c[i]; ++k) {
				temp = modAdd(temp, modMul(lol[k], r.a[k][j]));
			}
			fuck[j] = temp;
		}
		lol = fuck;
	}
	cout << lol[0] << endl;
	return 0;
}


#include<bits/stdc++.h>
#define int ll
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // yamin

const int maxn = 110;
ll a[maxn], b[maxn], c[maxn];

struct Matrix {
	int sz;
	vvi a;
	Matrix() {
		sz = 0;
	}
	Matrix(int sz) {
		this->sz = sz;
		a.assign(sz, vi(sz, 0));
	}
	friend Matrix Mul(const Matrix& p, const Matrix& q) {
		int sz = p.sz;
		Matrix r(sz);
		for(int k = 0; k < sz; ++k) {
			for(int i = 0; i < sz; ++i) {
				for(int j = 0; j < sz; ++j) {
					r.a[i][j] = modAdd(r.a[i][j], modMul(p.a[i][k], q.a[k][j]));
				}
			}
		}
		return r;
	}
};

Matrix Gen(int sz) {
	Matrix r(sz);
	for(int j = 0; j < sz; ++j) {
		if(j - 1 >= 0) r.a[j-1][j] = 1;
		r.a[j][j] = 1;
		if(j + 1 < sz) r.a[j+1][j] = 1;
	}
	return r;
}

Matrix unitaryMatrix(int sz) {
	Matrix r(sz);
	for(int i = 0; i < sz; ++i) r.a[i][i] = 1;
	return r;
}

Matrix Pow(Matrix b, ll p) {
	Matrix r = unitaryMatrix(b.sz);
	while(p > 0) {
		if(p&1LL) r = Mul(b, r);
		b = Mul(b, b);
		p >>= 1LL;
	}
	return r;
}

signed main() {
	int n, k; cin >> n >> k;
	for(int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i] >> c[i];
		++c[i];
	}
	b[n-1] = k;
	vi lol; lol.PB(1);
	for(int i = 0; i < n; ++i) {
		lol.resize(c[i]);
		vi fuck = lol;
		dbg(Gen(c[i]).a, b[i] - a[i]);
		Matrix r = Pow(Gen(c[i]), b[i] - a[i]);
		for(int j = 0; j < c[i]; ++j) {
			dbg(j);
			int temp = 0;
			for(int k = 0; k < c[i]; ++k) {
				temp = modAdd(temp, modMul(lol[k], r.a[k][j]));
			}
			fuck[j] = temp;
		}
		lol = fuck;
	}
	cout << lol[0] << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // yamin

const int maxn = 110;
ll a[maxn], b[maxn], c[maxn];

struct Matrix {
	int sz;
	vvi a;
	Matrix() {
		sz = 0;
	}
	Matrix(int sz) {
		this->sz = sz;
		a.assign(sz, vi(sz, 0));
	}
	friend Matrix Mul(const Matrix& p, const Matrix& q) {
		int sz = p.sz;
		Matrix r(sz);
		for(int k = 0; k < sz; ++k) {
			for(int i = 0; i < sz; ++i) {
				for(int j = 0; j < sz; ++j) {
					r.a[i][j] = modAdd(r.a[i][j], modMul(p.a[i][k], q.a[k][j]));
				}
			}
		}
		return r;
	}
};

Matrix Gen(int sz) {
	Matrix r(sz);
	for(int j = 0; j < sz; ++j) {
		if(j - 1 >= 0) r.a[j-1][j] = 1;
		r.a[j][j] = 1;
		if(j + 1 < sz) r.a[j+1][j] = 1;
	}
	return r;
}

Matrix unitaryMatrix(int sz) {
	Matrix r(sz);
	for(int i = 0; i < sz; ++i) r.a[i][i] = 1;
	return r;
}

Matrix Pow(Matrix b, ll p) {
	Matrix r = unitaryMatrix(b.sz);
	while(p > 0) {
		if(p&1LL) r = Mul(r, b);
		b = Mul(b, b);
		p >>= 1LL;
	}
	return r;
}

int main() {
	int n, k; cin >> n >> k;
	for(int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i] >> c[i];
		++c[i];
	}
	b[n-1] = k;
	vi lol; lol.PB(1);
	for(int i = 0; i < n; ++i) {
		lol.resize(c[i]);
		vi fuck = lol;
		dbg(Gen(c[i]).a, b[i] - a[i]);
		Matrix r = Pow(Gen(c[i]), b[i] - a[i]);
		for(int j = 0; j < c[i]; ++j) {
			dbg(j);
			int temp = 0;
			for(int k = 0; k < c[i]; ++k) {
				temp = modAdd(temp, modMul(lol[k], r.a[k][j]));
			}
			fuck[j] = temp;
		}
		lol = fuck;
	}
	cout << lol[0] << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // yamin

const int maxn = 110;
ll a[maxn], b[maxn], c[maxn];

struct Matrix {
	int sz;
	vvi a;
	Matrix() {
		sz = 0;
	}
	Matrix(int sz) {
		this->sz = sz;
		a.assign(sz, vi(sz, 0));
	}
	friend Matrix Mul(const Matrix& p, const Matrix& q) {
		int sz = p.sz;
		Matrix r(sz);
		for(int k = 0; k < sz; ++k) {
			for(int i = 0; i < sz; ++i) {
				for(int j = 0; j < sz; ++j) {
					r.a[i][j] = modAdd(r.a[i][j], modMul(p.a[i][k], q.a[k][j]));
				}
			}
		}
		return r;
	}
};

Matrix Gen(int sz) {
	Matrix r(sz);
	for(int j = 0; j < sz; ++j) {
		if(j - 1 >= 0) r.a[j-1][j] = 1;
		r.a[j][j] = 1;
		if(j + 1 < sz) r.a[j+1][j] = 1;
	}
	return r;
}

Matrix unitaryMatrix(int sz) {
	Matrix r(sz);
	for(int i = 0; i < sz; ++i) r.a[i][i] = 1;
	return r;
}

Matrix Pow(Matrix b, ll p) {
	Matrix r = unitaryMatrix(b.sz);
	while(p > 0) {
		if(p&1) r = Mul(r, b);
		b = Mul(b, b);
		p >>= 1LL;
	}
	return r;
}

int main() {
	int n, k; cin >> n >> k;
	for(int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i] >> c[i];
		++c[i];
	}
	b[n-1] = k;
	vi lol; lol.PB(1);
	for(int i = 0; i < n; ++i) {
		lol.resize(c[i]);
		vi fuck = lol;
		dbg(Gen(c[i]).a, b[i] - a[i]);
		Matrix r = Pow(Gen(c[i]), b[i] - a[i]);
		for(int j = 0; j < c[i]; ++j) {
			dbg(j);
			int temp = 0;
			for(int k = 0; k < c[i]; ++k) {
				temp = modAdd(temp, modMul(lol[k], r.a[k][j]));
			}
			fuck[j] = temp;
		}
		lol = fuck;
	}
	cout << lol[0] << endl;
	return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mtmax=20;
const int mod=1e9+7;
using namespace std;
ll k,l,r,cur[20],cur1[20];
int n,c,i,j;
struct matrix {
  ll m[mtmax][mtmax];
  matrix()
  {
     memset(m,0,sizeof(m));
  }
}b,ans;
matrix operator * (matrix x,matrix y)
{
	matrix c = matrix();
	for(int i=0;i<mtmax;i++)
	{
	 	for(int j=0;j<mtmax;j++)
	 	{
	 		for(int k=0;k<mtmax;k++)
	 		{
	 			c.m[i][j]=(c.m[i][j]+1LL*x.m[i][k]*y.m[k][j])%mod;
			}
		}
	}
	return c;
}
matrix pw(matrix m,ll n)
{
    matrix rs;
    for(int i=0;i<16;i++)rs.m[i][i]=1;
    while(n)
    {
    	if(n&1)rs=rs*m;
    	m=m*m;
    	n>>=1;
	}
	return rs;
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k;
	ans.m[0][0]=1;
	while(n--)
	{
		cin>>l>>r>>c;
		//for(i=c+1;i<=15;i++)ans.m[i][0]=0;
		for(i=0;i<=15;i++)for(j=0;j<=15;j++)b.m[i][j]=0;
		for(i=0;i<=c;i++)for(j=-1;j<2;j++)if(i+j>=0 && i+j<=c)b.m[i][i+j]=1;
		r=min(r,k)-l;
		ans=ans*pw(b,r);
	}
	cout<<ans.m[0][0]<<endl;
    return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mtmax=20;
const int mod=1e9+7;
using namespace std;
ll k,l,r,cur[20],cur1[20];
int n,c,i,j;
struct matrix {
  ll m[mtmax][mtmax];
  matrix()
  {
     memset(m,0,sizeof(m));
  }
}b,ans;
matrix operator * (matrix x,matrix y)
{
	matrix c = matrix();
	for(int i=0;i<mtmax;i++)
	{
	 	for(int j=0;j<mtmax;j++)
	 	{
	 		for(int k=0;k<mtmax;k++)
	 		{
	 			c.m[i][j]=(c.m[i][j]+1LL*x.m[i][k]*b.m[k][j])%mod;
			}
		}
	}
	return c;
}
matrix pw(matrix m,ll n)
{
    if(n==1)return m;
    matrix mid=pw(m,n/2);
    matrix out=mid*mid;
    if(n&1LL)out=out*m;
    return out;
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k;
	ans.m[0][0]=1;
	while(n--)
	{
		cin>>l>>r>>c;
		for(i=0;i<=15;i++)for(j=0;j<=15;j++)b.m[i][j]=0;
		for(i=0;i<=c;i++)for(j=-1;j<2;j++)if(i+j>=0 && i+j<=c)b.m[i][i+j]=1;
		r=min(r,k)-l;
		ans=ans*pw(b,r);
	}
	cout<<ans.m[0][0]<<endl;
    return 0;
}