#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;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int n,i,j,k;
ll f,l,r,c,ans[20][20],a[20][20],mul[20][20];
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>>f;
    for(i=0;i<20;i++)ans[i][i]=1;
    while(n--)
	{
		cin>>l>>r>>c;
		for(i=0;i<20;i++)for(j=0;j<20;j++)a[i][j]=0;
		for(i=0;i<=c;i++)for(j=-1;j<=1;j++)if(i+j>=0 && i+j<=c)a[i][i+j]=1;
		r=min(r,f)-l;
		while(r)
		{
			if(r&1)
			{
				for(i=0;i<20;i++)for(j=0;j<20;j++)mul[i][j]=0;
				for(i=0;i<20;i++)for(j=0;j<20;j++)for(k=0;k<20;k++)mul[i][j]=(mul[i][j]+ans[i][k]*a[k][j]%mod)%mod;
				for(i=0;i<20;i++)for(j=0;j<20;j++)ans[i][j]=mul[i][j];
			}
			for(i=0;i<20;i++)for(j=0;j<20;j++)mul[i][j]=0;
			for(i=0;i<20;i++)for(j=0;j<20;j++)for(k=0;k<20;k++)mul[i][j]=(mul[i][j]+a[i][k]*a[k][j]%mod)%mod;
			for(i=0;i<20;i++)for(j=0;j<20;j++)a[i][j]=mul[i][j];
			r>>=1;
		}
	}
	cout<<ans[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]*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;
int n,c,i,j;
struct matrix {
  ll m[mtmax][mtmax];
  matrix()
  {
     memset(m,0,sizeof(m));
  }
  matrix operator * (matrix b)
  {
     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*m[i][k]*b.m[k][j])%mod;
			}
		}
	 }
     return c;
  }
}b,ans;
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;
}


#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=16;
const int mod=1e9+7;
using namespace std;
ll k,l,r;
int n,c,i,j;
struct matrix {
  ll m[mtmax][mtmax];
  matrix()
  {
     memset(m,0,sizeof(m));
  }
  matrix operator * (matrix b)
  {
     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*m[i][k]*b.m[k][j])%mod;
			}
		}
	 }
     return c;
  }
}b,ans;
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;
}


#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));
  }
  matrix operator * (matrix b)
  {
     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*m[i][k]*b.m[k][j])%mod;
			}
		}
	 }
     return c;
  }
}b;
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;
	cur[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;
		matrix nw=pw(b,r);
		for(i=0;i<16;i++)cur1[i]=0;
		for(i=0;i<16;i++)
		{
			for(j=0;j<16;j++)
			{
				cur1[j]=(cur1[j]+cur[i]*nw.m[i][j]%mod)%mod;
			}
		}
		for(i=0;i<16;i++)cur[i]=cur1[i];
	}
	cout<<cur[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)
{
    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;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

//template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-5);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const unsigned long long mod = 1000000007;
struct Matrix {
    unsigned long long v[200][200];
    int row, col; // row x col
    Matrix(int n, int m, long long a = 0) {
        memset(v, 0, sizeof(v));
        row = n, col = m;
        for(int i = 0; i < row && i < col; i++)
            v[i][i] = a;
    }
    Matrix operator*(const Matrix& x) const {
        Matrix ret(row, x.col);
        for(int i = 0; i < row; i++) {
            for(int k = 0; k < col; k++) {
                if (v[i][k])
                    for(int j = 0; j < x.col; j++) {
                        ret.v[i][j] += v[i][k] * x.v[k][j],
                                ret.v[i][j] %= mod;
                    }
            }
        }
        return ret;
    }
    Matrix operator^(const long long& n) const {
        Matrix ret(row, col, 1), x = *this;
        long long y = n;
        while(y) {
            if(y&1)	ret = ret * x;
            y = y>>1, x = x * x;
        }
        return ret;
    }
};

const int H = 20, MAX_N = 101;
int n;
ll k, a[MAX_N], b[MAX_N];
int c[MAX_N];

Matrix solve(int i)
{
    if (i == n)
    {
        Matrix m(H, 1);
        m.v[0][0] = 1;
        return m;
    }
    Matrix m = solve(i + 1);
    for (int y = c[i] + 1; y < H; ++y)
        m.v[y][0] = 0;
    Matrix t(H, H);
    for (int y = 0; y <= c[i]; ++y)
    {
        for (int dy = -1; dy <= 1; ++dy)
        {
            int ny = y + dy;
            if (ny >= 0 && ny < H)
                t.v[y][ny] = 1;
        }
    }
    ll pwr = b[i] - a[i];
    t = t^pwr;
    m = t * m;
    return m;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    // checked editorial in this
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i] >> b[i] >> c[i];
    b[n - 1] = k;
    Matrix m = solve(0);
    cout << m.v[0][0] << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

//template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-5);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const unsigned long long mod = 1000000007;
struct Matrix {
    unsigned long long v[200][200];
    int row, col; // row x col
    Matrix(int n, int m, long long a = 0) {
        memset(v, 0, sizeof(v));
        row = n, col = m;
        for(int i = 0; i < row && i < col; i++)
            v[i][i] = a;
    }
    Matrix operator*(const Matrix& x) const {
        Matrix ret(row, x.col);
        for(int i = 0; i < row; i++) {
            for(int k = 0; k < col; k++) {
                if (v[i][k])
                    for(int j = 0; j < x.col; j++) {
                        ret.v[i][j] += v[i][k] * x.v[k][j],
                                ret.v[i][j] %= mod;
                    }
            }
        }
        return ret;
    }
    Matrix operator^(const long long& n) const {
        Matrix ret(row, col, 1), x = *this;
        long long y = n;
        while(y) {
            if(y&1)	ret = ret * x;
            y = y>>1, x = x * x;
        }
        return ret;
    }
};

const int H = 20, MAX_N = 101;
int n;
ll k, a[MAX_N], b[MAX_N];
int c[MAX_N];

Matrix solve(int i)
{
    if (i == n)
    {
        Matrix m(H, 1);
        m.v[0][0] = 1;
        return m;
    }
    Matrix m = solve(i + 1);
    for (int y = c[i] + 1; y < H; ++y)
        m.v[y][0] = 0;
    Matrix t(H, H);
    for (int y = 0; y < H; ++y)
    {
        for (int dy = -1; dy <= 1; ++dy)
        {
            int ny = y + dy;
            if (ny >= 0 && ny <= c[i])
                t.v[y][ny] = 1;
        }
    }
    ll pwr = b[i] - a[i];
    t = t^pwr;
    m = t * m;
    return m;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i] >> b[i] >> c[i];
    b[n - 1] = k;
    Matrix m = solve(0);
    cout << m.v[0][0] << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

//template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-5);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const unsigned long long mod = 1000000007;
struct Matrix {
    unsigned long long v[200][200];
    int row, col; // row x col
    Matrix(int n, int m, long long a = 0) {
        memset(v, 0, sizeof(v));
        row = n, col = m;
        for(int i = 0; i < row && i < col; i++)
            v[i][i] = a;
    }
    Matrix operator*(const Matrix& x) const {
        Matrix ret(row, x.col);
        for(int i = 0; i < row; i++) {
            for(int k = 0; k < col; k++) {
                if (v[i][k])
                    for(int j = 0; j < x.col; j++) {
                        ret.v[i][j] += v[i][k] * x.v[k][j],
                                ret.v[i][j] %= mod;
                    }
            }
        }
        return ret;
    }
    Matrix operator^(const long long& n) const {
        Matrix ret(row, col, 1), x = *this;
        long long y = n;
        while(y) {
            if(y&1)	ret = ret * x;
            y = y>>1, x = x * x;
        }
        return ret;
    }
};

const int H = 20, MAX_N = 101;
int n;
ll k, a[MAX_N], b[MAX_N];
int c[MAX_N];

Matrix solve(int i)
{
    if (i == n)
    {
        Matrix m(15, 1);
        m.v[0][0] = 1;
        return m;
    }
    Matrix m = solve(i + 1);
    for (int y = c[i] + 1; y < H; ++y)
        m.v[y][0] = 0;
    Matrix t(15, 15);
    for (int y = 0; y < H; ++y)
    {
        for (int dy = -1; dy <= 1; ++dy)
        {
            int ny = y + dy;
            if (ny >= 0 && ny <= c[i])
                t.v[y][ny] = 1;
        }
    }
    ll pwr = b[i] - a[i];
    t = t^pwr;
    m = t * m;
    return m;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i] >> b[i] >> c[i];
    b[n - 1] = k;
    Matrix m = solve(0);
    cout << m.v[0][0] << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

//template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-5);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const unsigned long long mod = 1000000007;
struct Matrix {
    unsigned long long v[200][200];
    int row, col; // row x col
    Matrix(int n, int m, long long a = 0) {
        memset(v, 0, sizeof(v));
        row = n, col = m;
        for(int i = 0; i < row && i < col; i++)
            v[i][i] = a;
    }
    Matrix operator*(const Matrix& x) const {
        Matrix ret(row, x.col);
        for(int i = 0; i < row; i++) {
            for(int k = 0; k < col; k++) {
                if (v[i][k])
                    for(int j = 0; j < x.col; j++) {
                        ret.v[i][j] += v[i][k] * x.v[k][j],
                                ret.v[i][j] %= mod;
                    }
            }
        }
        return ret;
    }
    Matrix operator^(const long long& n) const {
        Matrix ret(row, col, 1), x = *this;
        long long y = n;
        while(y) {
            if(y&1)	ret = ret * x;
            y = y>>1, x = x * x;
        }
        return ret;
    }
};

const int H = 16, MAX_N = 101;
int n;
ll k, a[MAX_N], b[MAX_N];
int c[MAX_N];

Matrix solve(int i)
{
    if (i == n)
    {
        Matrix m(H, 1);
        m.v[0][0] = 1;
        return m;
    }
    Matrix m = solve(i + 1);
    for (int y = c[i] + 1; y < H; ++y)
        m.v[y][0] = 0;
    Matrix t(H, H);
    for (int y = 0; y < H; ++y)
    {
        for (int dy = -1; dy <= 1; ++dy)
        {
            int ny = y + dy;
            if (ny >= 0 && ny <= c[i])
                t.v[y][ny] = 1;
        }
    }
    ll pwr = b[i] - a[i];
    t = t^pwr;
    m = t * m;
    return m;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    // checked editorial in this
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i] >> b[i] >> c[i];
    b[n - 1] = k;
    Matrix m = solve(0);
    cout << m.v[0][0] << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll inf = 1000000007;

vector<vector<ll> > dop;

void prin(vector<vector<ll> > a){
    cout << endl << endl;
    for(ll c=0; c<a.size(); c++){
        for(ll i=0; i<a[c].size(); i++)
            cout << a[c][i] << " ";
        cout << endl;
    }
}

vector<vector<ll> > mul(vector<vector<ll> > a, vector<vector<ll> > b){
    ll n = a.size();
    ll m = b[0].size();
    //prin(b);
    vector<vector<ll> > answ(n, vector<ll>(m));
    for(ll c=0; c<n; c++){
        for(ll i=0; i<m; i++){
            ll kol = 0;
            for(ll j=0; j<b.size(); j++){
                kol += a[c][j] * b[j][i];
                kol %= inf;
            }
            answ[c][i] = kol;
        }
    }
    return answ;
}

vector<vector<ll> > binpow(vector<vector<ll> > a, ll n){
    if(n == 1)return a;
    if(n % 2){
        return mul(binpow(a, n-1), a);
    }
    else {
        dop = binpow(a, n/2);
        return mul(dop, dop);
    }
}

int main()
{
    ll kol_vo, k;
    cin >> kol_vo >> k;
    vector<vector<ll> > all(16, vector<ll>(16));
    vector<vector<ll> > d(kol_vo, vector<ll>(3));
    for(ll c=0; c<kol_vo; c++)
        cin >> d[c][0] >> d[c][1] >> d[c][2];
    for(ll i=0; i<16; i++){
        if(i)all[i][i-1] = 1;
        all[i][i] = 1;
        if(i+1 != 16)all[i][i+1] = 1;
    }
    d[kol_vo-1][1] = k;
    //reverse(all.begin(), all.end());
    vector<vector<ll> > now = all;
    vector<vector<ll> > answ(1 ,vector<ll>(16));
    answ[0][0] = 1;
    for(ll c=0; c<kol_vo; c++){
        ll kol = d[c][1]-d[c][0]-1;
        for(ll i=d[c][2]+1; i<16; i++)
            for(ll j=0; j<16; j++)
                now[i][j] = 0;
        answ = mul(answ, now);
        //prin(answ);
        now = all;
        for(ll i=d[c][2]+1; i<16; i++)
            for(ll j=0; j<16; j++)
                now[i][j] = 0;
        if(kol > 0)answ = mul(answ, binpow(now, kol));
        //prin(answ);

    }
    //answ = mul(answ, now);
    cout << answ[0][0];
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll inf = 1000000007;

vector<vector<ll> > dop;

void prin(vector<vector<ll> > a){
    cout << endl << endl;
    for(ll c=0; c<a.size(); c++){
        for(ll i=0; i<a[c].size(); i++)
            cout << a[c][i] << " ";
        cout << endl;
    }
}

vector<vector<ll> > mul(vector<vector<ll> > a, vector<vector<ll> > b){
    ll n = a.size();
    ll m = b[0].size();
    //prin(b);
    vector<vector<ll> > answ(n, vector<ll>(m));
    for(ll c=0; c<n; c++){
        for(ll i=0; i<m; i++){
            ll kol = 0;
            for(ll j=0; j<b.size(); j++){
                kol += a[c][j] * b[j][i];
                kol %= inf;
            }
            answ[c][i] = kol;
        }
    }
    return answ;
}

vector<vector<ll> > binpow(vector<vector<ll> > a, ll n){
    if(n == 1)return a;
    if(n % 2){
        return mul(binpow(a, n-1), a);
    }
    else {
        dop = binpow(a, n/2);
        return mul(dop, dop);
    }
}

int main()
{
    ll kol_vo, k;
    cin >> kol_vo >> k;
    vector<vector<ll> > all(16, vector<ll>(16));
    vector<vector<ll> > d(kol_vo, vector<ll>(3));
    for(ll c=0; c<kol_vo; c++)
        cin >> d[c][0] >> d[c][1] >> d[c][2];
    for(ll i=0; i<16; i++){
        if(i)all[i][i-1] = 1;
        all[i][i] = 1;
        if(i+1 != 16)all[i][i+1] = 1;
    }
    //reverse(all.begin(), all.end());
    vector<vector<ll> > now = all;
    vector<vector<ll> > answ(1 ,vector<ll>(16));
    answ[0][0] = 1;
    for(ll c=0; c<kol_vo; c++){
        ll kol = d[c][1]-d[c][0]-1;
        if(c == kol_vo-1)kol = k-d[c][0];
        for(ll i=d[c][2]+1; i<16; i++)
            for(ll j=0; j<16; j++)
                now[i][j] = 0;
        if(c)answ = mul(answ, now);
        //prin(answ);
        now = all;
        for(ll i=d[c][2]+1; i<16; i++)
            for(ll j=0; j<16; j++)
                now[i][j] = 0;
        if(kol)answ = mul(answ, binpow(now, kol));
        //prin(answ);

    }
    //answ = mul(answ, now);
    cout << answ[0][0];
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll inf = 1000000007;

vector<vector<ll> > dop;

void prin(vector<vector<ll> > a){
    cout << endl << endl;
    for(ll c=0; c<a.size(); c++){
        for(ll i=0; i<a[c].size(); i++)
            cout << a[c][i] << " ";
        cout << endl;
    }
}

vector<vector<ll> > mul(vector<vector<ll> > a, vector<vector<ll> > b){
    ll n = a.size();
    ll m = b[0].size();
    //prin(b);
    vector<vector<ll> > answ(n, vector<ll>(m));
    for(ll c=0; c<n; c++){
        for(ll i=0; i<m; i++){
            ll kol = 0;
            for(ll j=0; j<b.size(); j++){
                kol += a[c][j] * b[j][i];
                kol %= inf;
            }
            answ[c][i] = kol;
        }
    }
    return answ;
}

vector<vector<ll> > binpow(vector<vector<ll> > a, ll n){
    if(n == 1)return a;
    if(n % 2){
        return mul(binpow(a, n-1), a);
    }
    else {
        dop = binpow(a, n/2);
        return mul(dop, dop);
    }
}

int main()
{
    ll kol_vo, k;
    cin >> kol_vo >> k;
    vector<vector<ll> > all(16, vector<ll>(16));
    vector<vector<ll> > d(kol_vo, vector<ll>(3));
    for(ll c=0; c<kol_vo; c++)
        cin >> d[c][0] >> d[c][1] >> d[c][2];
    for(ll i=0; i<16; i++){
        if(i)all[i][i-1] = 1;
        all[i][i] = 1;
        if(i+1 != 16)all[i][i+1] = 1;
    }
    //reverse(all.begin(), all.end());
    vector<vector<ll> > now = all;
    vector<vector<ll> > answ(1 ,vector<ll>(16));
    answ[0][0] = 1;
    for(ll c=0; c<kol_vo; c++){
        ll kol = d[c][1]-d[c][0]-1;
        if(c == kol_vo-1)kol = k-d[c][0];
        for(ll i=d[c][2]+1; i<16; i++)
            for(ll j=0; j<16; j++)
                now[j][i] = 0;
        if(c)answ = mul(answ, now);
        now = all;
        for(ll i=d[c][2]+1; i<16; i++)
            for(ll j=0; j<16; j++)
                now[j][i] = 0;
        //prin(now);
        if(kol)answ = mul(answ, binpow(now, kol));
        //prin(answ);

    }
    //answ = mul(answ, now);
    cout << answ[0][0];
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int inf = 1000000007;

vector<vector<int> > dop;

void prin(vector<vector<int> > &a){
    cout << endl << endl;
    for(int c=0; c<a.size(); c++){
        for(int i=0; i<a[c].size(); i++)
            cout << a[c][i] << " ";
        cout << endl;
    }
}

vector<vector<int> > mul(vector<vector<int> > a, vector<vector<int> > b){
    int n = a.size();
    int m = b[0].size();
    //prin(b);
    vector<vector<int> > answ(n, vector<int>(m));
    for(int c=0; c<n; c++){
        for(int i=0; i<m; i++){
            ll kol = 0;
            for(int j=0; j<b.size(); j++){
                kol += a[c][j] * b[j][i];
                kol %= inf;
            }
            answ[c][i] = kol;
        }
    }
    return answ;
}

vector<vector<int> > binpow(vector<vector<int> > a, int n){
    if(n == 1)return a;
    if(n % 2){
        return mul(binpow(a, n-1), a);
    }
    else {
        dop = binpow(a, n/2);
        return mul(dop, dop);
    }
}

int main()
{
    int kol_vo, k;
    cin >> kol_vo >> k;
    vector<vector<int> > aint(16, vector<int>(16));
    vector<vector<int> > d(kol_vo, vector<int>(3));
    for(int c=0; c<kol_vo; c++)
        cin >> d[c][0] >> d[c][1] >> d[c][2];
    for(int i=0; i<16; i++){
        if(i)aint[i][i-1] = 1;
        aint[i][i] = 1;
        if(i+1 != 16)aint[i][i+1] = 1;
    }
    d[kol_vo-1][1] = k;
    //reverse(aint.begin(), aint.end());
    vector<vector<int> > now = aint;
    vector<vector<int> > answ(1 ,vector<int>(16));
    answ[0][0] = 1;
    for(int c=0; c<kol_vo; c++){
        int kol = d[c][1]-d[c][0]-1;
        for(int i=d[c][2]+1; i<16; i++)
            for(int j=0; j<16; j++)
                now[i][j] = 0;
        answ = mul(answ, now);
        //prin(answ);
        now = aint;
        for(int i=d[c][2]+1; i<16; i++)
            for(int j=0; j<16; j++)
                now[i][j] = 0;
        if(kol)answ = mul(answ, binpow(now, kol));
        //prin(answ);

    }
    //answ = mul(answ, now);
    cout << answ[0][0];
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll inf = 1000000007;

vector<vector<ll> > dop;

void prin(vector<vector<ll> > a){
    cout << endl << endl;
    for(ll c=0; c<a.size(); c++){
        for(ll i=0; i<a[c].size(); i++)
            cout << a[c][i] << " ";
        cout << endl;
    }
}

vector<vector<ll> > mul(vector<vector<ll> > a, vector<vector<ll> > b){
    ll n = a.size();
    ll m = b[0].size();
    //prin(b);
    vector<vector<ll> > answ(n, vector<ll>(m));
    for(ll c=0; c<n; c++){
        for(ll i=0; i<m; i++){
            ll kol = 0;
            for(ll j=0; j<b.size(); j++){
                kol += a[c][j] * b[j][i];
                kol %= inf;
            }
            answ[c][i] = kol;
        }
    }
    return answ;
}

vector<vector<ll> > binpow(vector<vector<ll> > &a, ll n){
    if(n == 1)return a;
    if(n % 2){
        return mul(binpow(a, n-1), a);
    }
    else {
        dop = binpow(a, n/2);
        return mul(dop, dop);
    }
}

int main()
{
    ll kol_vo, k;
    cin >> kol_vo >> k;
    vector<vector<ll> > all(16, vector<ll>(16));
    vector<vector<ll> > d(kol_vo, vector<ll>(3));
    for(ll c=0; c<kol_vo; c++)
        cin >> d[c][0] >> d[c][1] >> d[c][2];
    for(ll i=0; i<16; i++){
        if(i)all[i][i-1] = 1;
        all[i][i] = 1;
        if(i+1 != 16)all[i][i+1] = 1;
    }
    d[kol_vo-1][1] = k;
    //reverse(all.begin(), all.end());
    vector<vector<ll> > now = all;
    vector<vector<ll> > answ(1 ,vector<ll>(16));
    answ[0][0] = 1;
    for(ll c=0; c<kol_vo; c++){
        ll kol = d[c][1]-d[c][0]-1;
        for(ll i=d[c][2]+1; i<16; i++)
            for(ll j=0; j<16; j++)
                now[i][j] = 0;
        answ = mul(answ, now);
        //prin(answ);
        now = all;
        for(ll i=d[c][2]+1; i<16; i++)
            for(ll j=0; j<16; j++)
                now[i][j] = 0;
        if(kol)answ = mul(answ, binpow(now, kol));
        //prin(answ);

    }
    //answ = mul(answ, now);
    cout << answ[0][0];
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll inf = 1000000007;

vector<vector<ll> > dop;

void prin(vector<vector<ll> > a){
    cout << endl << endl;
    for(ll c=0; c<a.size(); c++){
        for(ll i=0; i<a[c].size(); i++)
            cout << a[c][i] << " ";
        cout << endl;
    }
}

vector<vector<ll> > answf;

void init(int n, int m){
    answf.resize(n, vector<ll>(m));
}

vector<vector<ll> > mul(vector<vector<ll> > &a, vector<vector<ll> > &b){
    ll n = a.size();
    ll m = b[0].size();
    //prin(b);
    for(ll c=0; c<n; c++){
        for(ll i=0; i<m; i++){
            ll kol = 0;
            for(ll j=0; j<b.size(); j++){
                kol += a[c][j] * b[j][i];
                kol %= inf;
            }
            answ[c][i] = kol;
        }
    }
    return answ;
}

vector<vector<ll> > binpow(vector<vector<ll> > &a, ll n){
    if(n == 1)return a;
    if(n % 2){
        return mul(binpow(a, n-1), a);
    }
    else {
        dop = binpow(a, n/2);
        return mul(dop, dop);
    }
}

int main()
{
    ll kol_vo, k;
    cin >> kol_vo >> k;
    init(16, 16);
    vector<vector<ll> > all(16, vector<ll>(16));
    vector<vector<ll> > d(kol_vo, vector<ll>(3));
    for(ll c=0; c<kol_vo; c++)
        cin >> d[c][0] >> d[c][1] >> d[c][2];
    for(ll i=0; i<16; i++){
        if(i)all[i][i-1] = 1;
        all[i][i] = 1;
        if(i+1 != 16)all[i][i+1] = 1;
    }
    d[kol_vo-1][1] = k;
    //reverse(all.begin(), all.end());
    vector<vector<ll> > now = all;
    vector<vector<ll> > answ(1 ,vector<ll>(16));
    answ[0][0] = 1;
    for(ll c=0; c<kol_vo; c++){
        ll kol = d[c][1]-d[c][0]-1;
        for(ll i=d[c][2]+1; i<16; i++)
            for(ll j=0; j<16; j++)
                now[i][j] = 0;
        answ = mul(answ, now);
        //prin(answ);
        now = all;
        for(ll i=d[c][2]+1; i<16; i++)
            for(ll j=0; j<16; j++)
                now[i][j] = 0;
        if(kol)answ = mul(answ, binpow(now, kol));
        //prin(answ);

    }
    //answ = mul(answ, now);
    cout << answ[0][0];
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n;
ll k;
ll a[105], b[105];
int c[105];
ll dp[105][16];
struct mat {
	ll a[16][16];
};
mat mul(mat a, mat b){
	mat ans;
	for(int i=0;i<=15;i++){
		for(int j=0;j<=15;j++){
			ans.a[i][j]=0;
			for(int k=0;k<=15;k++){
				ans.a[i][j]=(ans.a[i][j]+a.a[i][k]*b.a[k][j])%mod;
			}
		}
	}
	return ans;
}
mat power(mat base, ll p){
	mat ans;
	for(int i=0;i<=15;i++){
		for(int j=0;j<=15;j++){
			ans.a[i][j]=(i==j);
		}
	}
	while(p){
		if(p&1){
			ans=mul(ans, base);
		}
		p>>=1;
		base=mul(base, base);
	}
	return ans;
}

int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i];
	b[n]=k;
	memset(dp, 0, sizeof(dp));
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		mat ans;
		memset(ans.a, 0, sizeof(ans.a));
		for(int j=0;j<=c[i];j++){
			for(int k=0;k<=15;k++){
				if(abs(k-j)<=1&&k<=c[i])ans.a[j][k]=1;
			}
		}
		mat trans=power(ans, b[i]-a[i]);
		for(int j=0;j<=15;j++)if(j>c[i])dp[i-1][j]=0;
		for(int j=0;j<=15;j++){
			for(int k=0;k<=15;k++){
				dp[i][j]=(dp[i][j]+dp[i-1][k]*trans.a[j][k])%mod;
			}
		}
	}
	printf("%lld\n", dp[n][0]);
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
const int maxn = 100010;
const int mod = 1e9+7;
typedef long long ll;
struct Mat{
	ll a[20][20];
};
Mat mul(Mat x,Mat y){
	Mat m;
	memset(m.a,0,sizeof(m.a));
	for(int i = 0;i<=15;i++)
		for(int j = 0;j<=15;j++)
			for(int k = 0;k<=15;k++)
				m.a[i][j] = (m.a[i][j] + (x.a[i][k] * y.a[k][j]%mod))%mod;
	return m;
}
Mat pow(Mat base,int n){
	Mat ret;
	for(int i = 0;i<=15;i++)
		for(int j = 0;j<=15;j++)
			ret.a[i][j] = (i == j);
	while(n){
		if(n & 1){
			ret = mul(ret,base);
		}
		n >>= 1;
		base = mul(base,base);
	}
	return ret;
}
ll a[110],b[110],c[110];
ll dp[110][16];
void print(Mat m){
	for(int i = 0;i<=15;i++){
		for(int j = 0;j<=15;j++)
			cout<<m.a[i][j]<<' ';
		cout<<endl;
	}
}
int main(){
	// freopen("a.in","r",stdin);
	ll n,k;
	scanf("%I64d%I64d",&n,&k);
	for(int i = 1;i<=n;i++)
		scanf("%I64d%I64d%I64d",&a[i],&b[i],&c[i]);
	b[n] = min(b[n],k);
	Mat ans;
	Mat B;
	memset(ans.a,0,sizeof(ans.a));
	dp[0][0] = 1;
	for(int i = 1;i<=n;i++){
		// cout<<' '<<i<<endl;
		memset(B.a,0,sizeof(B.a));
		for(int j = 0;j<=c[i];j++){
			B.a[j][j] = 1;
			if(j < c[i])
				B.a[j][j+1] = 1;
			if(j > 0)
				B.a[j][j-1] = 1;
		}
		B = pow(B,b[i]-a[i]);
		// print(B);
		for(int j = 0;j<=15;j++){
			for(int k = 0;k<=15;k++){
				dp[i][j] += dp[i-1][k] * B.a[j][k];
				dp[i][j] %= mod;
			}
		}
	}
	printf("%I64d\n",dp[n][0]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n;
ll k;
ll a[105], b[105];
int c[105];
ll dp[105][15];
struct mat {
	ll a[16][16];
};
mat mul(mat a, mat b){
	mat ans;
	for(int i=0;i<=15;i++){
		for(int j=0;j<=15;j++){
			ans.a[i][j]=0;
			for(int k=0;k<=15;k++){
				ans.a[i][j]=(ans.a[i][j]+a.a[i][k]*b.a[k][j])%mod;
			}
		}
	}
	return ans;
}
mat power(mat base, ll p){
	mat ans;
	for(int i=0;i<=15;i++){
		for(int j=0;j<=15;j++){
			ans.a[i][j]=(i==j);
		}
	}
	while(p){
		if(p&1){
			ans=mul(ans, base);
		}
		p>>=1;
		base=mul(base, base);
	}
	return ans;
}

int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i];
	b[n]=k;
	memset(dp, 0, sizeof(dp));
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		mat ans;
		memset(ans.a, 0, sizeof(ans.a));
		for(int j=0;j<=c[i];j++){
			for(int k=0;k<=15;k++){
				if(abs(k-j)<=1)ans.a[j][k]=1;
			}
		}
		mat trans=power(ans, b[i]-a[i]);
		for(int j=0;j<=15;j++)if(j>c[i])dp[i-1][j]=0;
		for(int j=0;j<=15;j++){
			for(int k=0;k<=15;k++){
				dp[i][j]=(dp[i][j]+dp[i-1][k]*trans.a[j][k])%mod;
			}
		}
	}
	printf("%lld\n", dp[n][0]);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n;
ll k;
ll a[105], b[105];
int c[105];
ll dp[105][15];
struct mat {
	ll a[16][16];
};
mat mul(mat a, mat b){
	mat ans;
	for(int i=0;i<=15;i++){
		for(int j=0;j<=15;j++){
			ans.a[i][j]=0;
			for(int k=0;k<=15;k++){
				ans.a[i][j]=(ans.a[i][j]+a.a[i][k]*b.a[k][j])%mod;
			}
		}
	}
	return ans;
}
mat power(mat base, ll p){
	mat ans;
	for(int i=0;i<=15;i++){
		for(int j=0;j<=15;j++){
			ans.a[i][j]=(i==j);
		}
	}
	while(p){
		if(p&1){
			ans=mul(ans, base);
		}
		p>>=1;
		base=mul(base, base);
	}
	return ans;
}

int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i];
	b[n]=k;
	memset(dp, 0, sizeof(dp));
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		mat ans;
		memset(ans.a, 0, sizeof(ans.a));
		for(int j=0;j<=c[i];j++){
			for(int k=0;k<=15;k++){
				if(abs(k-j)<=1&&k<=c[i])ans.a[j][k]=1;
			}
		}
		mat trans=power(ans, b[i]-a[i]);
		for(int j=0;j<=15;j++){
			for(int k=0;k<=15;k++){
				dp[i][j]=(dp[i][j]+dp[i-1][k]*trans.a[j][k])%mod;
			}
		}
	}
	printf("%lld\n", dp[n][0]);
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
const int mod = 1e9+7;
typedef long long ll;
/*struct Mat{
	ll a[101][101];
};
Mat mul(Mat x,Mat y){
	Mat m;
	for(int i = 0;i<=15;i++){
		for(int j = 0;j<=15;j++){
			m.a[i][j] = 0;
			for(int k = 0;k<=15;k++){
				m.a[i][j] = (m.a[i][j] + x.a[i][k] * y.a[k][j])%mod;
			}
		}
	}
	return m;
}
Mat B,ret;
void Pow(int n){
	for(int i = 0;i<=15;i++)
		for(int j = 0;j<=15;j++)
			ret.a[i][j] = (i == j);
	while(n){
		if(n & 1){
			ret = mul(ret,B);
		}
		n >>= 1;
		B = mul(B,B);
	}
}*/
struct mat {
	ll a[16][16];
};
mat mul(mat a, mat b){
	mat ans;
	for(int i=0;i<=15;i++){
		for(int j=0;j<=15;j++){
			ans.a[i][j]=0;
			for(int k=0;k<=15;k++){
				ans.a[i][j]=(ans.a[i][j]+a.a[i][k]*b.a[k][j])%mod;
			}
		}
	}
	return ans;
}
mat power(mat base, ll p){
	mat ans;
	for(int i=0;i<=15;i++){
		for(int j=0;j<=15;j++){
			ans.a[i][j]=(i==j);
		}
	}
	while(p){
		if(p&1){
			ans=mul(ans, base);
		}
		p>>=1;
		base=mul(base, base);
	}
	return ans;
}

ll a[110],b[110];
int c[110];
ll dp[110][16];
int n;
ll k;
int main(){
	// freopen("a.in","r",stdin);
	scanf("%d%lld",&n,&k);
	for(int i = 1;i<=n;i++)
		scanf("%lld%lld%d",&a[i],&b[i],&c[i]);
	b[n] = k;
	dp[0][0] = 1;
	for(int i = 1;i<=n;i++){
		mat B;
		memset(B.a, 0, sizeof(B));
		for(int j = 0;j<=c[i];j++){
			B.a[j][j] = 1;
			if(j < c[i])
				B.a[j][j+1] = 1;
			if(j > 0)
				B.a[j][j-1] = 1;
		}
		mat ret=power(B, b[i]-a[i]);
		for(int j = 0;j<=15;j++){
			for(int k = 0;k<=15;k++){
				dp[i][j] = (dp[i][j]+dp[i-1][k] * ret.a[j][k])%mod;
			}
		}
	}
	printf("%lld\n",dp[n][0]);
	return 0;
}


#include <iostream>
#include <vector>
#define MOD 1000000007

using namespace std;

vector<vector<int> > mat;

vector<vector<int> > matmul(vector<vector<int> > &a, vector<vector<int> > &b) {
    vector<vector<int> > mat2(a.size(), vector<int>(a.size(), 0));
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) {
            for (int k = 0; k < a.size(); k++) {
                mat2[i][j] += a[i][k] * b[k][j];
                mat2[i][j] %= MOD;
            }
        }
    }
    return mat2;
}

vector<int> vecmul(vector<int> &a, vector<vector<int> > &b) {
    vector<int> mat2(a.size(), 0);
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) { // cout << i << " " << j << " " << a[i] << " " << b[i][j] << endl;
            mat2[i] += a[j] * b[j][i];
            mat2[i] %= MOD;
        }
    }
    return mat2;
}

vector<vector<int> > matexp(int a) {
    if (a == 1) return mat;
    vector<vector<int> > mat2 = matexp(a / 2), mat3 = matmul(mat2, mat2);
    if (a % 2) return matmul(mat, mat3);
    return matmul(mat2, mat2);
}

void construct_mat(int a) {
    mat = vector<vector<int> >(a, vector<int>(a, 0));
    for (int i = 0; i < a; i++) mat[i][(i - 1 >= 0 ? i - 1 : i)] = mat[i][i] = mat[i][(i + 1 < a ? i + 1 : i)] = 1;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k; cin >> n >> k;
    vector<int> cur = {1};
    for (int i = 0; i < n; i++) {
        int a, b, c; cin >> a >> b >> c;
        if (a >= k) break;
        cur.resize(c + 1, 0);
        construct_mat(c + 1);
        // for (int i = 0; i <= c; i++) { for (int j = 0; j <= c; j++) cout << mat[i][j] << " "; cout << endl; } cout << endl;
        vector<vector<int> > prod = matexp(min(b, k) - a);
        // for (int i = 0; i <= c; i++) { for (int j = 0; j <= c; j++) cout << prod[i][j] << " "; cout << endl; } cout << endl;
        cur = vecmul(cur, prod);
        // for (int i = 0; i <= c; i++) cout << cur[i] << " "; cout << endl;
    }
    cout << cur[0] << endl;
    return 0;
}


#include <iostream>
#include <vector>
#define MOD 1000000007

using namespace std;

vector<vector<int> > mat;

void matmul(vector<vector<int> > &a, vector<vector<int> > &b, vector<vector<int> > &c) {
    vector<vector<int> > mat2(a.size(), vector<int>(a.size(), 0));
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) {
            for (int k = 0; k < a.size(); k++) {
                mat2[i][j] += a[i][k] * b[k][j];
                mat2[i][j] %= MOD;
            }
        }
    }
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) c[i][j] = mat2[i][j];
    }
}

void vecmul(vector<int> &a, vector<vector<int> > &b, vector<int> &c) {
    vector<int> mat2(a.size(), 0);
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) {
            mat2[i] += a[j] * b[j][i];
            mat2[i] %= MOD;
        }
    }
    for (int i = 0; i < a.size(); i++) c[i] = mat2[i];
}

vector<vector<int> > matexp(long long a) {
    vector<vector<int> > mat2(mat.size(), vector<int>(mat.size(), 0));
    for (int i = 0; i < mat.size(); i++) mat2[i][i] = 1;
    while (a) {
        if (a % 2) { matmul(mat2, mat, mat2); a--; }
        else { matmul(mat, mat, mat); a /= 2; }
    }
    return mat2;
}

void construct_mat(int a) {
    mat = vector<vector<int> >(a, vector<int>(a, 0));
    for (int i = 0; i < a; i++) mat[i][(i - 1 >= 0 ? i - 1 : i)] = mat[i][i] = mat[i][(i + 1 < a ? i + 1 : i)] = 1;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    long long n, k; scanf("%lld %lld", &n, &k);
    vector<int> cur = {1};
    for (int i = 0; i < n; i++) {
        long long a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
        if (a >= k) break;
        cur.resize(c + 1, 0);
        construct_mat(c + 1);
        vector<vector<int> > prod = matexp(min(b, k) - a);
        vecmul(cur, prod, cur);
    }
    printf("%d\n", cur[0]);
    return 0;
}


#include <iostream>
#include <vector>
#define MOD 1000000007

using namespace std;

vector<vector<int> > mat;

void matmul(vector<vector<int> > &a, vector<vector<int> > &b, vector<vector<int> > &c) {
    vector<vector<int> > mat2(a.size(), vector<int>(a.size(), 0));
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) {
            for (int k = 0; k < a.size(); k++) {
                mat2[i][j] += a[i][k] * b[k][j];
                mat2[i][j] %= MOD;
            }
        }
    }
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) c[i][j] = mat2[i][j];
    }
}

void vecmul(vector<int> &a, vector<vector<int> > &b, vector<int> &c) {
    vector<int> mat2(a.size(), 0);
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) { // cout << i << " " << j << " " << a[i] << " " << b[i][j] << endl;
            mat2[i] += a[j] * b[j][i];
            mat2[i] %= MOD;
        }
    }
    for (int i = 0; i < a.size(); i++) c[i] = mat2[i];
}

vector<vector<int> > matexp(int a) {
    vector<vector<int> > mat2(mat.size(), vector<int>(mat.size(), 0));
    for (int i = 0; i < mat.size(); i++) mat2[i][i] = 1;
    while (a) {
        if (a % 2) { matmul(mat2, mat, mat2); a--; }
        else { matmul(mat, mat, mat); a /= 2; }
        /*
        int c = mat.size() - 1;
        for (int i = 0; i <= c; i++) { for (int j = 0; j <= c; j++) cout << mat[i][j] << " "; cout << endl; } cout << endl;
        for (int i = 0; i <= c; i++) { for (int j = 0; j <= c; j++) cout << mat2[i][j] << " "; cout << endl; } cout << endl;
        */
    }
    return mat2;
}

void construct_mat(int a) {
    mat = vector<vector<int> >(a, vector<int>(a, 0));
    for (int i = 0; i < a; i++) mat[i][(i - 1 >= 0 ? i - 1 : i)] = mat[i][i] = mat[i][(i + 1 < a ? i + 1 : i)] = 1;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k; scanf("%d %d", &n, &k);
    vector<int> cur = {1};
    for (int i = 0; i < n; i++) {
        int a, b, c; scanf("%d %d %d", &a, &b, &c);
        if (a >= k) break;
        cur.resize(c + 1, 0);
        construct_mat(c + 1);
        // for (int i = 0; i <= c; i++) { for (int j = 0; j <= c; j++) cout << mat[i][j] << " "; cout << endl; } cout << endl;
        vector<vector<int> > prod = matexp(min(b, k) - a);
        // for (int i = 0; i <= c; i++) { for (int j = 0; j <= c; j++) cout << prod[i][j] << " "; cout << endl; } cout << endl;
        vecmul(cur, prod, cur);
        // for (int i = 0; i <= c; i++) cout << cur[i] << " "; cout << endl;
    }
    printf("%d\n", cur[0]);
    return 0;
}


#include <iostream>
#include <vector>
#define MOD 1000000007

using namespace std;

vector<vector<int> > mat;

void matmul(vector<vector<int> > &a, vector<vector<int> > &b, vector<vector<int> > &c) {
    vector<vector<int> > mat2(a.size(), vector<int>(a.size(), 0));
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) {
            for (int k = 0; k < a.size(); k++) {
                mat2[i][j] += a[i][k] * b[k][j];
                mat2[i][j] %= MOD;
            }
        }
    }
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) c[i][j] = mat2[i][j];
    }
}

vector<int> vecmul(vector<int> &a, vector<vector<int> > &b) {
    vector<int> mat2(a.size(), 0);
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) { // cout << i << " " << j << " " << a[i] << " " << b[i][j] << endl;
            mat2[i] += a[j] * b[j][i];
            mat2[i] %= MOD;
        }
    }
    return mat2;
}

vector<vector<int> > matexp(int a) {
    vector<vector<int> > mat2(mat.size(), vector<int>(mat.size(), 0));
    for (int i = 0; i < mat.size(); i++) mat2[i][i] = 1;
    while (a) {
        if (a % 2) { matmul(mat2, mat, mat2); a--; }
        else { matmul(mat, mat, mat); a /= 2; }
        /*
        int c = mat.size() - 1;
        for (int i = 0; i <= c; i++) { for (int j = 0; j <= c; j++) cout << mat[i][j] << " "; cout << endl; } cout << endl;
        for (int i = 0; i <= c; i++) { for (int j = 0; j <= c; j++) cout << mat2[i][j] << " "; cout << endl; } cout << endl;
        */
    }
    return mat2;
}

void construct_mat(int a) {
    mat = vector<vector<int> >(a, vector<int>(a, 0));
    for (int i = 0; i < a; i++) mat[i][(i - 1 >= 0 ? i - 1 : i)] = mat[i][i] = mat[i][(i + 1 < a ? i + 1 : i)] = 1;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k; cin >> n >> k;
    vector<int> cur = {1};
    for (int i = 0; i < n; i++) {
        int a, b, c; cin >> a >> b >> c;
        if (a >= k) break;
        cur.resize(c + 1, 0);
        construct_mat(c + 1);
        // for (int i = 0; i <= c; i++) { for (int j = 0; j <= c; j++) cout << mat[i][j] << " "; cout << endl; } cout << endl;
        vector<vector<int> > prod = matexp(min(b, k) - a);
        // for (int i = 0; i <= c; i++) { for (int j = 0; j <= c; j++) cout << prod[i][j] << " "; cout << endl; } cout << endl;
        cur = vecmul(cur, prod);
        // for (int i = 0; i <= c; i++) cout << cur[i] << " "; cout << endl;
    }
    cout << cur[0] << endl;
    return 0;
}


#include <iostream>
#include <vector>
#define MOD 1000000007

using namespace std;

vector<vector<long long> > mat;

void matmul(vector<vector<long long> > &a, vector<vector<long long> > &b, vector<vector<long long> > &c) {
    vector<vector<long long> > mat2(a.size(), vector<long long>(a.size(), 0));
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) {
            for (int k = 0; k < a.size(); k++) {
                mat2[i][j] += a[i][k] * b[k][j];
                mat2[i][j] %= MOD;
            }
        }
    }
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) c[i][j] = mat2[i][j];
    }
}

void vecmul(vector<long long> &a, vector<vector<long long> > &b, vector<long long> &c) {
    vector<long long> mat2(a.size(), 0);
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a.size(); j++) {
            mat2[i] += a[j] * b[j][i];
            mat2[i] %= MOD;
        }
    }
    for (int i = 0; i < a.size(); i++) c[i] = mat2[i];
}

vector<vector<long long> > matexp(long long a) {
    vector<vector<long long> > mat2(mat.size(), vector<long long>(mat.size(), 0));
    for (int i = 0; i < mat.size(); i++) mat2[i][i] = 1;
    while (a) {
        if (a % 2) { matmul(mat2, mat, mat2); a--; }
        else { matmul(mat, mat, mat); a /= 2; }
    }
    return mat2;
}

void construct_mat(long long a) {
    mat = vector<vector<long long> >(a, vector<long long>(a, 0));
    for (int i = 0; i < a; i++) mat[i][(i - 1 >= 0 ? i - 1 : i)] = mat[i][i] = mat[i][(i + 1 < a ? i + 1 : i)] = 1;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    long long n, k; scanf("%lld %lld", &n, &k);
    vector<long long> cur = {1};
    for (int i = 0; i < n; i++) {
        long long a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
        if (a >= k) break;
        cur.resize(c + 1, 0);
        construct_mat(c + 1);
        vector<vector<long long> > prod = matexp(min(b, k) - a);
        vecmul(cur, prod, cur);
    }
    printf("%lld\n", cur[0]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define all(v) (v).begin(),(v).end()
#define sz(v) (v).size()
#define int long long
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
bool desc_sort(const int & lhs,const int & rhs)
{
    return lhs>rhs;
}
bool desc_pii_sort(const pii & lhs , const pii & rhs)
{
    return lhs>rhs;
}
bool second_sort(const pii & lhs , const pii & rhs)
{
    pii a,b;
    a.F = lhs.S;
    a.S = lhs.F;
    b.F = rhs.S;
    b.S = rhs.F;
    return a<b;
}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
#else
    #define trace(...)
#endif

// #define int long long
#define modd 1000000007

inline ll fast_expo(ll base,ll power,ll modulo=modd){
    base%=modulo;
    if (base<0LL) base+=modulo;
    ll x=base,cnt=power,ans=1LL;
    while(cnt){
        if (cnt&1LL) ans=(ans*x)%modulo;
        x=(x*x)%modulo;
        cnt>>=1LL;
    }
    // int tmp=ans;
    return ans;
}
inline ll inv(ll base,ll modulo=modd){
    return fast_expo(base,modulo-2LL,modulo);
}

vector<vector<ll>> iden[17];
vector<vector<ll>> mat_mult(vector<vector<ll>> a,vector<vector<ll>> b,int n)
{
    vector<vector<ll>> c;
    c.assign(n,vi(n));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int k=0;k<n;k++)
            {
                c[i][j] = (c[i][j] + a[i][k]*b[k][j])%modd;
            }
        }
    }
    return c;
}
vector<vector<ll>> mat_square(vector<vector<ll>> a,int n)
{
    return mat_mult(a,a,n);
}
vector<vector<ll>> mat_pow(vector<vector<ll>> a, ll k,int n)
{
    if(k==0LL)
    {
        return iden[n];
    }
    else if(k&1LL)
    {
        return mat_mult(a,mat_square(mat_pow(a,k>>1LL,n),n),n);
    }
    else
    {
        return mat_square(mat_pow(a,k>>1LL,n),n);
    }
}

signed main()
{
    #ifdef _SUBLIME
    ifstream cin("input.txt");
    ofstream cout("output.txt");
    #endif
    fio;
    int n,k;
    cin>>n>>k;
    int a[n+1],b[n+1],c[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];
    b[n]=k;
    for(int i=1;i<=16;i++)
    {
        iden[i].assign(i,vi(i));
        for(int j=0;j<i;j++)
            iden[i][j][j]=1;
    }
    ll dp[n+1][16];
    for(int i=0;i<16;i++)
        dp[0][i]=0;
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        int d = b[i]-a[i];
        if(c[i]==0)
        {
            dp[i][0]=dp[i-1][0];
            for(int j=1;j<=15;j++)
                dp[i][j]=0;
            continue;
        }
        vector<vi> mat(c[i]+1,vi(c[i]+1,0));
        mat[0][0]=1;mat[c[i]][c[i]]=1;
        mat[0][1]=1;mat[c[i]][c[i]-1]=1;
        for(int j=1;j<c[i];j++)
            mat[j][j-1]=mat[j][j]=mat[j][j+1]=1;
        mat = mat_pow(mat,d,c[i]+1);
        for(int j=0;j<=c[i];j++)
        {
            dp[i][j]=0;
            for(int l=0;l<=c[i];l++)
            {
                dp[i][j] = (dp[i][j] + (mat[j][l]*dp[i-1][l])%modd)%modd;
            }
        }
        for(int j=c[i]+1;j<=15;j++)
            dp[i][j]=0;
    }
    d1(dp[n][0]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define all(v) (v).begin(),(v).end()
#define sz(v) (v).size()
#define int long long
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
bool desc_sort(const int & lhs,const int & rhs)
{
    return lhs>rhs;
}
bool desc_pii_sort(const pii & lhs , const pii & rhs)
{
    return lhs>rhs;
}
bool second_sort(const pii & lhs , const pii & rhs)
{
    pii a,b;
    a.F = lhs.S;
    a.S = lhs.F;
    b.F = rhs.S;
    b.S = rhs.F;
    return a<b;
}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
#else
    #define trace(...)
#endif

// #define int long long
#define modd 1000000007

inline ll fast_expo(ll base,ll power,ll modulo=modd){
    base%=modulo;
    if (base<0LL) base+=modulo;
    ll x=base,cnt=power,ans=1LL;
    while(cnt){
        if (cnt&1LL) ans=(ans*x)%modulo;
        x=(x*x)%modulo;
        cnt>>=1LL;
    }
    // int tmp=ans;
    return ans;
}
inline ll inv(ll base,ll modulo=modd){
    return fast_expo(base,modulo-2LL,modulo);
}

vector<vector<ll>> iden[17];
vector<vector<ll>> mat_mult(vector<vector<ll>> a,vector<vector<ll>> b,int n)
{
    vector<vector<ll>> c;
    c.assign(n,vi(n));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int k=0;k<n;k++)
            {
                c[i][j] = (c[i][j] + a[i][k]*b[k][j])%modd;
            }
        }
    }
    return c;
}
vector<vector<ll>> mat_square(vector<vector<ll>> a,int n)
{
    return mat_mult(a,a,n);
}
vector<vector<ll>> mat_pow(vector<vector<ll>> a, ll k,int n)
{
    if(k==0LL)
    {
        return iden[n];
    }
    else if(k&1LL)
    {
        return mat_mult(a,mat_square(mat_pow(a,k>>1LL,n),n),n);
    }
    else
    {
        return mat_square(mat_pow(a,k>>1LL,n),n);
    }
}

signed main()
{
    #ifdef _SUBLIME
    ifstream cin("input.txt");
    ofstream cout("output.txt");
    #endif
    fio;
    int n,k;
    cin>>n>>k;
    int a[n+1],b[n+1],c[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];
    b[n]=k;
    for(int i=1;i<=16;i++)
    {
        iden[i].assign(i,vi(i));
        for(int j=0;j<i;j++)
            iden[i][j][j]=1;
    }
    ll dp[n+1][16];
    for(int i=0;i<16;i++)
        dp[0][i]=0;
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        int d = b[i]-a[i];
        vector<vi> mat(c[i]+1,vi(c[i]+1,0));
        mat[0][0]=1;mat[c[i]][c[i]]=1;
        mat[0][1]=1;mat[c[i]][c[i]-1]=1;
        for(int j=1;j<c[i];j++)
            mat[j][j-1]=mat[j][j]=mat[j][j+1]=1;
        mat = mat_pow(mat,d,c[i]+1);
        for(int j=0;j<=c[i];j++)
        {
            dp[i][j]=0;
            for(int l=0;l<=c[i];l++)
            {
                dp[i][j] = (dp[i][j] + (mat[j][l]*dp[i-1][l])%modd)%modd;
            }
        }
        for(int j=c[i]+1;j<=15;j++)
            dp[i][j]=0;
    }
    d1(dp[n][0]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define all(v) (v).begin(),(v).end()
#define sz(v) (v).size()
#define int long long
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
bool desc_sort(const int & lhs,const int & rhs)
{
    return lhs>rhs;
}
bool desc_pii_sort(const pii & lhs , const pii & rhs)
{
    return lhs>rhs;
}
bool second_sort(const pii & lhs , const pii & rhs)
{
    pii a,b;
    a.F = lhs.S;
    a.S = lhs.F;
    b.F = rhs.S;
    b.S = rhs.F;
    return a<b;
}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
#else
    #define trace(...)
#endif

// #define int long long
#define modd 1000000007

inline ll fast_expo(ll base,ll power,ll modulo=modd){
    base%=modulo;
    if (base<0LL) base+=modulo;
    ll x=base,cnt=power,ans=1LL;
    while(cnt){
        if (cnt&1LL) ans=(ans*x)%modulo;
        x=(x*x)%modulo;
        cnt>>=1LL;
    }
    // int tmp=ans;
    return ans;
}
inline ll inv(ll base,ll modulo=modd){
    return fast_expo(base,modulo-2LL,modulo);
}

vector<vector<ll>> iden[17];
vector<vector<ll>> mat_mult(vector<vector<ll>> a,vector<vector<ll>> b,int n)
{
    vector<vector<ll>> c;
    c.assign(n,vi(n));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int k=0;k<n;k++)
            {
                c[i][j] = (c[i][j] + a[i][k]*b[k][j])%modd;
            }
        }
    }
    return c;
}
vector<vector<ll>> mat_square(vector<vector<ll>> a,int n)
{
    return mat_mult(a,a,n);
}
vector<vector<ll>> mat_pow(vector<vector<ll>> a, ll k,int n)
{
    if(k==0LL)
    {
        return iden[n];
    }
    else if(k&1LL)
    {
        return mat_mult(a,mat_square(mat_pow(a,k>>1LL,n),n),n);
    }
    else
    {
        return mat_square(mat_pow(a,k>>1LL,n),n);
    }
}

signed main()
{
    #ifdef _SUBLIME
    ifstream cin("input.txt");
    ofstream cout("output.txt");
    #endif
    fio;
    int n,k;
    cin>>n>>k;
    int a[n+1],b[n+1],c[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];
    b[n]=k;
    for(int i=1;i<=16;i++)
    {
        iden[i].assign(i,vi(i));
        for(int j=0;j<i;j++)
            iden[i][j][j]=1;
    }
    ll dp[n+1][16];
    for(int i=0;i<16;i++)
        dp[0][i]=0;
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        int d = b[i]-a[i];
        if(c[i]==0)
        {
            dp[i][0]=dp[i-1][0];
            for(int j=1;j<=15;j++)
                dp[i][j]=0;
            continue;
        }
        vector<vi> mat(c[i]+1,vi(c[i]+1,0));
        mat[0][0]=1;mat[c[i]][c[i]]=1;
        mat[0][1]=1;mat[c[i]][c[i]-1]=1;
        for(int j=1;j<c[i];j++)
            mat[j][j-1]=mat[j][j]=mat[j][j+1]=1;
        mat = mat_pow(mat,d,c[i]+1);
        for(int j=0;j<=c[i];j++)
        {
            dp[i][j]=0;
            for(int l=0;l<=15;l++)
            {
                dp[i][j] = (dp[i][j] + (mat[j][l]*dp[i-1][l])%modd)%modd;
            }
        }
        for(int j=c[i]+1;j<=15;j++)
            dp[i][j]=0;
    }
    d1(dp[n][0]);
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define all(v) (v).begin(),(v).end()
#define sz(v) (v).size()
#define int long long
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
bool desc_sort(const int & lhs,const int & rhs)
{
    return lhs>rhs;
}
bool desc_pii_sort(const pii & lhs , const pii & rhs)
{
    return lhs>rhs;
}
bool second_sort(const pii & lhs , const pii & rhs)
{
    pii a,b;
    a.F = lhs.S;
    a.S = lhs.F;
    b.F = rhs.S;
    b.S = rhs.F;
    return a<b;
}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
#else
    #define trace(...)
#endif

// #define int long long
#define modd 1000000007

inline ll fast_expo(ll base,ll power,ll modulo=modd){
    base%=modulo;
    if (base<0LL) base+=modulo;
    ll x=base,cnt=power,ans=1LL;
    while(cnt){
        if (cnt&1LL) ans=(ans*x)%modulo;
        x=(x*x)%modulo;
        cnt>>=1LL;
    }
    // int tmp=ans;
    return ans;
}
inline ll inv(ll base,ll modulo=modd){
    return fast_expo(base,modulo-2LL,modulo);
}

vector<vector<ll>> iden[17];
vector<vector<ll>> mat_mult(vector<vector<ll>> a,vector<vector<ll>> b,int n)
{
    vector<vector<ll>> c;
    c.assign(n,vi(n));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int k=0;k<n;k++)
            {
                c[i][j] = (c[i][j] + a[i][k]*b[k][j])%modd;
            }
        }
    }
    return c;
}
vector<vector<ll>> mat_square(vector<vector<ll>> a,int n)
{
    return mat_mult(a,a,n);
}
vector<vector<ll>> mat_pow(vector<vector<ll>> a, ll k,int n)
{
    if(k==0LL)
    {
        return iden[n];
    }
    else if(k&1LL)
    {
        return mat_mult(a,mat_square(mat_pow(a,k>>1LL,n),n),n);
    }
    else
    {
        return mat_square(mat_pow(a,k>>1LL,n),n);
    }
}

signed main()
{
    #ifdef _SUBLIME
    ifstream cin("input.txt");
    ofstream cout("output.txt");
    #endif
    fio;
    int n,k;
    cin>>n>>k;
    int a[n+1],b[n+1],c[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];
    b[n]=k;
    for(int i=1;i<=16;i++)
    {
        iden[i].assign(i,vi(i));
        for(int j=0;j<i;j++)
            iden[i][j][j]=1;
    }
    ll dp[n+1][16];
    for(int i=0;i<16;i++)
        dp[0][i]=0;
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        int d = b[i]-a[i];
        if(c[i]==0)
        {
            dp[i][0]=dp[i-1][0];
            for(int j=1;j<=15;j++)
                dp[i][j]=0;
            continue;
        }
        vector<vi> mat(c[i]+1,vi(c[i]+1,0));
        mat[0][0]=1;mat[c[i]][c[i]]=1;
        mat[0][1]=1;mat[c[i]][c[i]-1]=1;
        for(int j=1;j<c[i];j++)
            mat[j][j-1]=mat[j][j]=mat[j][j+1]=1;
        mat = mat_pow(mat,d,c[i]+1);
        for(int j=0;j<=c[i];j++)
        {
            dp[i][j]=0;
            for(int l=0;l<=c[i];l++)
            {
                dp[i][j] = (dp[i][j] + (mat[j][l]*dp[i-1][l])%modd)%modd;
            }
        }
        for(int j=c[i]+1;j<=15;j++)
            dp[i][j]=0;
    }
    d1(dp[n][0]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    long long a[16][16];
}one,dp;
const long long mo=1e9+7;
node mult(node a,node b)
{
    int i,j,k;
    node c;
    memset(c.a,0,sizeof(c.a));
    for(i=0;i<16;i++)
    {
        for(j=0;j<16;j++)
        {
            for(k=0;k<16;k++)
            {
                c.a[i][j]=(c.a[i][j]+(a.a[i][k]*b.a[k][j])%mo)%mo;
            }
        }
    }
    return c;
}
node pow(node a,long long w)
{
    node ans;
    memset(ans.a,0,sizeof(ans.a));
    for(int i=0;i<16;i++)
        ans.a[i][i]=1;
    while(w)
    {
        if(w&1)
        {
            ans=mult(ans,a);
        }
        a=mult(a,a);
        w>>=1;
    }
    return ans;
}
int main()
{
    int i,j,tempc;
    long long n,k,tempa,tempb;
    for(i=0;i<16;i++)
    {
        for(j=max(0,i-1);j<=min(15,i+1);j++)
        one.a[j][i]=1;
    }
    cin>>n>>k;
    dp.a[0][0]=1;
    while(n--)
    {
        scanf("%lld %lld %d",&tempa,&tempb,&tempc);
        node temp=one;
        for(i=tempc+1;i<16;i++)
        {
            for(j=0;j<16;j++)
                temp.a[j][i]=0;
        }
        dp=mult(dp,pow(temp,min(tempb,k)-tempa));
    }
    cout<<dp.a[0][0]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    long long a[16][16];
}one,dp;
const int mo=1e9+7;
node mult(node a,node b)
{
    int i,j,k;
    node c;
    memset(c.a,0,sizeof(c.a));
    for(i=0;i<16;i++)
    {
        for(j=0;j<16;j++)
        {
            for(k=0;k<16;k++)
            {
                c.a[i][j]=(c.a[i][j]+a.a[i][k]*b.a[k][j])%mo;
            }
        }
    }
    return c;
}
node pow(node a,long long w)
{
    node ans;
    memset(ans.a,0,sizeof(ans.a));
    for(int i=0;i<16;i++)
        ans.a[i][i]=1;
    while(w)
    {
        if(w&1)
        {
            ans=mult(ans,a);
        }
        a=mult(a,a);
        w>>=1;
    }
    return ans;
}
int main()
{
    int i,j,tempc;
    long long n,k,tempa,tempb;
    for(i=0;i<16;i++)
    {
        for(j=max(0,i-1);j<=min(15,i+1);j++)
        one.a[j][i]=1;
    }
    cin>>n>>k;
    dp.a[0][0]=1;
    while(n--)
    {
        scanf("%lld %lld %d",&tempa,&tempb,&tempc);
        node temp=one;
        for(i=tempc+1;i<16;i++)
        {
            for(j=0;j<16;j++)
                temp.a[j][i]=0;
        }
        dp=mult(dp,pow(temp,min(tempb,k)-tempa));
    }
    cout<<dp.a[0][0]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    long long a[16][16];
}one,dp;
const long long mo=1e9+7;
node mult(node a,node b)
{
    int i,j,k;
    node c;
    memset(c.a,0,sizeof(c.a));
    for(i=0;i<16;i++)
    {
        for(j=0;j<16;j++)
        {
            for(k=0;k<16;k++)
            {
                c.a[i][j]=(c.a[i][j]+a.a[i][k]*b.a[k][j])%mo;
            }
        }
    }
    return c;
}
node pow(node a,long long w)
{
    node ans;
    memset(ans.a,0,sizeof(ans.a));
    for(int i=0;i<16;i++)
        ans.a[i][i]=1;
    while(w)
    {
        if(w&1)
        {
            ans=mult(ans,a);
        }
        a=mult(a,a);
        w>>=1;
    }
    return ans;
}
int main()
{
    int i,j,tempc;
    long long n,k,tempa,tempb;
    for(i=0;i<16;i++)
    {
        for(j=max(0,i-1);j<=min(15,i+1);j++)
        one.a[j][i]=1;
    }
    cin>>n>>k;
    dp.a[0][0]=1;
    while(n--)
    {
        scanf("%lld %lld %d",&tempa,&tempb,&tempc);
        node temp=one;
        for(i=tempc+1;i<16;i++)
        {
            for(j=0;j<16;j++)
                temp.a[j][i]=0;
        }
        dp=mult(dp,pow(temp,min(tempb,k)-tempa));
    }
    cout<<dp.a[0][0]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    long long a[16][16];
}one,dp;
const int mo=1e9+7;
node mult(node a,node b)
{
    int i,j,k;
    node c;
    memset(c.a,0,sizeof(c.a));
    for(i=0;i<16;i++)
    {
        for(j=0;j<16;j++)
        {
            for(k=0;k<16;k++)
            {
                c.a[i][j]=(c.a[i][j]+a.a[i][k]*b.a[k][j])%mo;
            }
        }
    }
    return c;
}
node pow(node a,long long w)
{
    node ans;
    memset(ans.a,0,sizeof(ans.a));
    for(int i=0;i<16;i++)
        ans.a[i][i]=1;
    while(w)
    {
        if(w&1)
        {
            ans=mult(ans,a);
        }
        a=mult(a,a);
        w>>=1;
    }
    return ans;
}
int main()
{
    int i,j,tempc;
    long long n,k,tempa,tempb;
    for(i=0;i<16;i++)
    {
        for(j=max(0,i-1);j<=min(15,i+1);j++)
        one.a[j][i]=1;
    }
    cin>>n>>k;
    dp.a[0][0]=1;
    while(n--)
    {
        scanf("%I64d %I64d %d",&tempa,&tempb,&tempc);
        node temp=one;
        temp.a[tempc+1][tempc]=0;
        for(i=tempc+1;i<16;i++)
        {
            for(j=0;j<16;j++)
                temp.a[j][i]=0;
        }
        dp=mult(dp,pow(temp,min(tempb,k)-tempa));
    }
    cout<<dp.a[0][0]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    long long a[16][16];
}one,dp;
const int mo=1e9+7;
node mult(node a,node b)
{
    int i,j,k;
    node c;
    memset(c.a,0,sizeof(c.a));
    for(i=0;i<16;i++)
    {
        for(j=0;j<16;j++)
        {
            for(k=0;k<16;k++)
            {
                c.a[i][j]=(c.a[i][j]+a.a[i][k]*b.a[k][j])%mo;
            }
        }
    }
    return c;
}
node pow(node a,long long w)
{
    node ans;
    memset(ans.a,0,sizeof(ans.a));
    for(int i=0;i<16;i++)
        ans.a[i][i]=1;
    while(w)
    {
        if(w&1)
        {
            ans=mult(ans,a);
        }
        a=mult(a,a);
        w>>=1;
    }
    return ans;
}
int main()
{
    int i,j,tempc;
    long long n,k,tempa,tempb;
    for(i=0;i<16;i++)
    {
        for(j=max(0,i-1);j<=min(15,i+1);j++)
        one.a[j][i]=1;
    }
    cin>>n>>k;
    dp.a[0][0]=1;
    while(n--)
    {
        scanf("%I64d %I64d %d",&tempa,&tempb,&tempc);
        node temp=one;
        for(i=tempc+1;i<16;i++)
        {
            for(j=0;j<16;j++)
                temp.a[j][i]=0;
        }
        dp=mult(dp,pow(temp,min(tempb,k)-tempa));
    }
    cout<<dp.a[0][0]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<long long,long long> pi;
typedef pair<pi,long long> pii;
long long mod=1e9+7;
long long id[15][15];
long long a[105],b[105],c[105];
vector<pii> line;
struct matrix{
    long long n,m;
    vector<vector<long long> > a;
    matrix (long long x,long long y)
    {
        n=x;
        m=y;
        a.assign(x,vector<long long>(y,0));
    }
    matrix operator * (matrix b)
    {
        long long p=b.m;
        matrix c(n,p);
        for(long long i=0;i<n;i++)
        for(long long k=0;k<m;k++)
        for(long long j=0;j<p;j++)
        {
            c.a[i][j]+=a[i][k]*b.a[k][j];
            c.a[i][j]%=mod;
        }
        return c;
    }
};
matrix pw(matrix x,long long y)
{
     matrix res(x.n,x.m);
     res=x;
     y--;
     while(y)
     {
         if(y&1) res=res*x;
         y>>=1;
         x=x*x;
     }
     return res;
}
int main()
{
    ios_base::sync_with_stdio(0);
    long long n,m;
    long long k;
    cin>>n>>k;
    long long l=0,r=0,y=0;
    c[0]=0;
    for(long long i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
        if(c[i]==c[i-1])
        {
            r=b[i];
        }
        else
        {
            if(r!=0)
            line.push_back(pii(pi(l,r),c[i-1]));
            l=a[i];
            r=b[i];
        }
        if(i==n)
        line.push_back(pii((pi(l,r)),c[i]));
    }
    matrix b(16,16);
    matrix a(1,16);
    a.a[0][0]=1;
    long long ymax=0;
  //  cout<<line.size()<<"\n";
    for(long long i=0;i<line.size();i++)
    {
        long long y=line[i].second;
        long long l=line[i].first.first;
        long long r=line[i].first.second;
        for(long long ij=0;ij<16;ij++)
        for(long long ji=0;ji<16;ji++)
        {
            b.a[ij][ji]=0;
        }
        if(ymax>y)
        {
            for(long long i=y+1;i<16;i++)
                a.a[0][i]=0;
            ymax=y;
        }
        ymax=max(ymax,y);
        for(long long ij=0;ij<=y;ij++)
        {
            b.a[ij][max(0ll,ij-1)]=1;
            b.a[ij][ij]=1;
            b.a[ij][min(y,ij+1)]=1;
        }
        a=a*pw(b,min(k,r)-l);
        //cout<<a.a[0][0]<<" "<<y<<"\n";
    }
    cout<<a.a[0][0]%mod;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<long long,long long> pi;
typedef pair<pi,long long> pii;
long long mod=1e9+7;
long long id[15][15];
long long a[105],b[105],c[105];
vector<pii> line;
struct matrix{
    long long n,m;
    vector<vector<long long> > a;
    matrix (long long x,long long y)
    {
        n=x;
        m=y;
        a.assign(x,vector<long long>(y,0));
    }
    matrix operator * (matrix b)
    {
        long long p=b.m;
        matrix c(n,p);
        for(long long i=0;i<n;i++)
        for(long long k=0;k<m;k++)
        for(long long j=0;j<p;j++)
        {
            c.a[i][j]+=a[i][k]*b.a[k][j];
            c.a[i][j]%=mod;
        }
        return c;
    }
};
matrix pw(matrix x,long long y)
{
     matrix res(x.n,x.m);
     res=x;
     y--;
     while(y)
     {
         if(y&1) res=res*x;
         y>>=1;
         x=x*x;
     }
     return res;
}
int main()
{
    ios_base::sync_with_stdio(0);
    long long n,m;
    long long k;
    cin>>n>>k;
    long long l=0,r=0,y=0;
    for(long long i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
        if(c[i]==c[i-1])
        {
            r=b[i];
        }
        else
        {
            line.push_back(pii(pi(l,r),c[i-1]));
            l=a[i];
            r=b[i];
        }
        if(i==n)
        line.push_back(pii((pi(l,k)),c[i]));
    }

    matrix b(16,16);
    matrix a(1,16);
    a.a[0][0]=1;
    long long ymax=0;
    for(long long i=0;i<line.size();i++)
    {
        long long y=line[i].second;
        long long l=line[i].first.first;
        long long r=line[i].first.second;
        for(long long ij=0;ij<16;ij++)
        for(long long ji=0;ji<16;ji++)
        {
            b.a[ij][ji]=0;
        }
        if(ymax>y)
        {
            for(long long i=y+1;i<16;i++)
                a.a[0][i]=0;
            ymax=y;
        }
        ymax=max(ymax,y);
        for(long long ij=0;ij<=y;ij++)
        {
            b.a[ij][max(0ll,ij-1)]=1;
            b.a[ij][ij]=1;
            b.a[ij][min(y,ij+1)]=1;
        }
        a=a*pw(b,min(k,r)-l);
        //cout<<a.a[0][0]<<" "<<y<<"\n";
    }
    cout<<a.a[0][0]%mod;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<long long,long long> pi;
typedef pair<pi,long long> pii;
long long mod=1e9+7;
long long id[15][15];
long long a[105],b[105];
vector<pii> line;
struct matrix{
    long long n,m;
    vector<vector<long long> > a;
    matrix (long long x,long long y)
    {
        n=x;
        m=y;
        a.assign(x,vector<long long>(y,0));
    }
    matrix operator * (matrix b)
    {
        long long p=b.m;
        matrix c(n,p);
        for(long long i=0;i<n;i++)
        for(long long k=0;k<m;k++)
        for(long long j=0;j<p;j++)
        {
            c.a[i][j]+=a[i][k]*b.a[k][j];
            c.a[i][j]%=mod;
        }
        return c;
    }
};
matrix pw(matrix x,long long y)
{
     matrix res(x.n,x.m);
     res=x;
     y--;
     while(y)
     {
         if(y&1) res=res*x;
         y>>=1;
         x=x*x;
     }
     return res;
}
int main()
{
    long long n,m;
    long long k;
    cin>>n>>k;
    long long l=0,r=0,y=0;
    for(long long i=1;i<=n;i++)
    {
        long long a,b;
        long long c;
        cin>>a>>b>>c;
        line.push_back(pii((pi(a,b)),c));
    }
    matrix b(16,16);
    matrix a(1,16);
    a.a[0][0]=1;
    long long ymax=0;
    for(long long i=0;i<line.size();i++)
    {
        long long y=line[i].second;
        long long l=line[i].first.first;
        long long r=line[i].first.second;
        for(long long ij=0;ij<16;ij++)
        for(long long ji=0;ji<16;ji++)
        {
            b.a[ij][ji]=0;
        }
        if(ymax>y)
        {
            for(long long i=y+1;i<16;i++)
                a.a[0][i]=0;
            ymax=y;
        }
        ymax=max(ymax,y);
        for(long long ij=0;ij<=y;ij++)
        {
            b.a[ij][max(0ll,ij-1)]=1;
            b.a[ij][ij]=1;
            b.a[ij][min(y,ij+1)]=1;
        }
        a=a*pw(b,min(k,r)-l);
        //cout<<a.a[0][0]<<" "<<y<<"\n";
    }
    cout<<a.a[0][0]%mod;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<long long,long long> pi;
typedef pair<pi,long long> pii;
long long mod=1e9+7;
long long id[15][15];
long long a[105],b[105],c[105];
vector<pii> line;
struct matrix{
    long long n,m;
    vector<vector<long long> > a;
    matrix (long long x,long long y)
    {
        n=x;
        m=y;
        a.assign(x,vector<long long>(y,0));
    }
    matrix operator * (matrix b)
    {
        long long p=b.m;
        matrix c(n,p);
        for(long long i=0;i<n;i++)
        for(long long k=0;k<m;k++)
        for(long long j=0;j<p;j++)
        {
            c.a[i][j]+=a[i][k]*b.a[k][j];
            c.a[i][j]%=mod;
        }
        return c;
    }
};
matrix pw(matrix x,long long y)
{
     matrix res(x.n,x.m);
     res=x;
     y--;
     while(y)
     {
         if(y&1) res=res*x;
         y>>=1;
         x=x*x;
     }
     return res;
}
int main()
{
    ios_base::sync_with_stdio(0);
    long long n,m;
    long long k;
    cin>>n>>k;
    long long l=0,r=0,y=0;
    c[0]=0;
    for(long long i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
        if(c[i]==c[i-1])
        {
            r=b[i];
        }
        else
        {
            if(r!=0)
            line.push_back(pii(pi(l,min(r,k)),c[i-1]));
            l=a[i];
            r=b[i];
        }
        if(i==n)
        line.push_back(pii((pi(l,min(r,k))),c[i]));
    }
    matrix b(16,16);
    matrix a(1,16);
    a.a[0][0]=1;
    long long ymax=0;
   //cout<<line.size()<<"\n";
    for(long long i=0;i<line.size();i++)
    {
        long long y=line[i].second;
        long long l=line[i].first.first;
        long long r=line[i].first.second;

        for(long long ij=0;ij<16;ij++)
        for(long long ji=0;ji<16;ji++)
        {
            b.a[ij][ji]=0;
        }
        if(ymax>y)
        {
            for(long long i=y+1;i<16;i++)
                a.a[0][i]=0;
            ymax=y;
        }
        ymax=max(ymax,y);
        for(long long ij=0;ij<=y;ij++)
        {
            b.a[ij][max(0ll,ij-1)]=1;
            b.a[ij][ij]=1;
            b.a[ij][min(y,ij+1)]=1;
        }
        if(min(k,r)-l)
        a=a*pw(b,min(k,r)-l);
       // printf("%lld %lld %lld\n",l,r,y);
        //cout<<a.a[0][0]<<" "<<y<<"\n";
    }
    cout<<a.a[0][0]%mod;
}


#include <cstdio>
#include <algorithm>
#define mod 1000000007
const int MAXN = 105, MAXM = 16;
int n;
long long k;
long long dp[MAXM];
using namespace std;
struct Segment
{
    long long a, b;
    int c;
}seg[MAXN];
void new_matrix(long long** &matrix)
{
    matrix = new long long*[MAXM];
    for (int i = 0; i < MAXM; i ++)
    {
        matrix[i] = new long long[MAXM];
        for (int j = 0; j < MAXM; j ++)
            matrix[i][j] = 0;
    }
}
void delete_matrix(long long** &matrix)
{
    for (int i = 0; i < MAXM; i ++)
        delete matrix[i];
    delete matrix;
}
void multiply(long long** a, long long** b, long long** c)
{
    for (int i = 0; i < MAXM; i ++)
        for (int j = 0; j < MAXM; j ++)
        {
            c[i][j] = 0;
            for (int k = 0; k < MAXM; k ++)
                c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % mod;
        }
}
void quick_pow(long long** base, long long index, long long** res)
{
    if (index == 0)
    {
        for (int i = 0; i < MAXM; i ++)
            res[i][i] = 1;
        return;
    }
    long long **temp;
    new_matrix(temp);
    quick_pow(base, index >> 1, temp);
    multiply(temp, temp, res);
    if (index & 1)
    {
        for (int i = 0; i < MAXM; i ++)
            for (int j = 0; j < MAXM; j ++)
                temp[i][j] = res[i][j];
        multiply(temp, base, res);
    }
    delete_matrix(temp);
}
void solve(int x)
{
    long long **base, **res;
    new_matrix(base);
    new_matrix(res);
    for (int i = 0; i <= seg[x].c; i ++)
    {
        if (i > 0) base[i][i - 1] = 1;
        base[i][i] = 1;
        if (i < seg[x].c) base[i][i + 1] = 1;
    }
    quick_pow(base, seg[x].b - seg[x].a, res);
    long long *temp = new long long[MAXM];
    for (int i = 0; i < MAXM; i ++)
    {
        temp[i] = 0;
        for (int j = 0; j < MAXM; j ++)
            temp[i] = (temp[i] + dp[j] * res[i][j]) % mod;
    }
    for (int i = 0; i < MAXM; i ++)
        dp[i] = temp[i];
    delete_matrix(base);
    delete_matrix(res);
    delete temp;
}
int main()
{
    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i ++)
        scanf("%lld%lld%d", &seg[i].a, &seg[i].b, &seg[i].c);
    seg[n].b = k;
    dp[0] = 1;
    for (int i = 1; i <= n; i ++)
        solve(i);
    printf("%lld", dp[0]);
    return 0;
}


#include <cstdio>
#include <algorithm>
#define mod 1000000007
const int MAXN = 105, MAXM = 16;
int n;
long long k;
long long dp[MAXM];
using namespace std;
struct Segment
{
    long long a, b;
    int c;
}seg[MAXN];
long long** new_matrix()
{
    long long** matrix = new long long*[MAXM];
    for (int i = 0; i < MAXM; i ++)
    {
        matrix[i] = new long long[MAXM];
        for (int j = 0; j < MAXM; j ++)
            matrix[i][j] = 0;
    }
    return matrix;
}
void delete_matrix(long long** &matrix)
{
    for (int i = 0; i < MAXM; i ++)
        delete matrix[i];
    delete matrix;
}
void multiply(long long** a, long long** b, long long** c)
{
    for (int i = 0; i < MAXM; i ++)
        for (int j = 0; j < MAXM; j ++)
        {
            c[i][j] = 0;
            for (int k = 0; k < MAXM; k ++)
                c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % mod;
        }
}
void quick_pow(long long** base, long long index, long long** res)
{
    if (index == 0)
    {
        for (int i = 0; i < MAXM; i ++)
            res[i][i] = 1;
        return;
    }
    long long **temp = new_matrix();
    quick_pow(base, index >> 1, temp);
    multiply(temp, temp, res);
    if (index & 1)
    {
        for (int i = 0; i < MAXM; i ++)
            for (int j = 0; j < MAXM; j ++)
                temp[i][j] = res[i][j];
        multiply(temp, base, res);
    }
    delete_matrix(temp);
}
void solve(int x)
{
    long long **base = new_matrix(), **res = new_matrix();
    for (int i = 0; i <= seg[x].c; i ++)
    {
        if (i > 0) base[i][i - 1] = 1;
        base[i][i] = 1;
        if (i < seg[x].c) base[i][i + 1] = 1;
    }
    quick_pow(base, seg[x].b - seg[x].a, res);
    long long *temp = new long long[MAXM];
    for (int i = 0; i < MAXM; i ++)
    {
        temp[i] = 0;
        for (int j = 0; j < MAXM; j ++)
            temp[i] = (temp[i] + dp[j] * res[i][j]) % mod;
    }
    for (int i = 0; i < MAXM; i ++)
        dp[i] = temp[i];
    delete_matrix(base);
    delete_matrix(res);
    delete temp;
}
int main()
{
    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i ++)
        scanf("%lld%lld%d", &seg[i].a, &seg[i].b, &seg[i].c);
    seg[n].b = k;
    dp[0] = 1;
    for (int i = 1; i <= n; i ++)
        solve(i);
    printf("%lld", dp[0]);
    return 0;
}


#include <cstdio>
#include <algorithm>
#define mod 1000000007
const int MAXN = 105, MAXM = 16;
int n;
long long k;
long long dp[MAXM];
using namespace std;
struct Segment
{
    long long a, b;
    int c;
}seg[MAXN];
void new_matrix(long long** &matrix)
{
    matrix = new long long*[MAXM];
    for (int i = 0; i < MAXM; i ++)
    {
        matrix[i] = new long long[MAXM];
        for (int j = 0; j < MAXM; j ++)
            matrix[i][j] = 0;
    }
}
void delete_matrix(long long** &matrix)
{
    for (int i = 0; i < MAXM; i ++)
        delete matrix[i];
    delete matrix;
}
void multiply(long long** a, long long** b, long long** c)
{
    for (int i = 0; i < MAXM; i ++)
        for (int j = 0; j < MAXM; j ++)
        {
            c[i][j] = 0;
            for (int k = 0; k < MAXM; k ++)
                c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % mod;
        }
}
void quick_pow(long long** base, long long index, long long** res)
{
    if (index == 1)
    {
        for (int i = 0; i < MAXM; i ++)
            for (int j = 0; j < MAXM; j ++)
                res[i][j] = base[i][j];
        return;
    }
    long long **temp;
    new_matrix(temp);
    quick_pow(base, index >> 1, temp);
    multiply(temp, temp, res);
    if (index & 1)
    {
        for (int i = 0; i < MAXM; i ++)
            for (int j = 0; j < MAXM; j ++)
                temp[i][j] = res[i][j];
        multiply(temp, base, res);
    }
    delete_matrix(temp);
}
void solve(int x)
{
    long long **base, **res;
    new_matrix(base);
    new_matrix(res);
    for (int i = 0; i <= seg[x].c; i ++)
    {
        if (i > 0) base[i][i - 1] = 1;
        base[i][i] = 1;
        if (i < seg[x].c) base[i][i + 1] = 1;
    }
    quick_pow(base, seg[x].b - seg[x].a, res);
    /*for (int i = 0; i < MAXM; i ++)
    {
        for (int j = 0; j < MAXM; j ++)
            printf("%lld ", res[i][j]);
        printf("\n");
    }*/
    long long *temp = new long long[MAXM];
    for (int i = 0; i < MAXM; i ++)
    {
        temp[i] = 0;
        for (int j = 0; j < MAXM; j ++)
            temp[i] = (temp[i] + dp[j] * res[i][j]) % mod;
    }
    for (int i = 0; i < MAXM; i ++)
        dp[i] = temp[i];
    delete_matrix(base);
    delete_matrix(res);
    delete temp;
}
int main()
{
    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i ++)
        scanf("%lld%lld%d", &seg[i].a, &seg[i].b, &seg[i].c);
    seg[n].b = k;
    if (seg[n].a == seg[n].b) n--;
    dp[0] = 1;
    for (int i = 1; i <= n; i ++)
        solve(i);
    printf("%lld", dp[0]);
    return 0;
}


#include <cstdio>
#include <algorithm>
#define mod 1000000007
const int MAXN = 105, MAXM = 15;
int n;
long long k;
long long dp[MAXM];
using namespace std;
struct Segment
{
    long long a, b;
    int c;
}seg[MAXN];
void new_matrix(long long** &matrix)
{
    matrix = new long long*[MAXM];
    for (int i = 0; i < MAXM; i ++)
    {
        matrix[i] = new long long[MAXM];
        for (int j = 0; j < MAXM; j ++)
            matrix[i][j] = 0;
    }
}
void delete_matrix(long long**& matrix)
{
    for (int i = 0; i < MAXM; i ++)
        delete matrix[i];
    delete matrix;
}
void multiply(long long** a, long long** b, long long** c)
{
    for (int i = 0; i < MAXM; i ++)
        for (int j = 0; j < MAXM; j ++)
        {
            c[i][j] = 0;
            for (int k = 0; k < MAXM; k ++)
                c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % mod;
        }
}
void quick_pow(long long** base, long long index, long long** res)
{
    if (index == 1)
    {
        for (int i = 0; i < MAXM; i ++)
            for (int j = 0; j < MAXM; j ++)
                res[i][j] = base[i][j];
        return;
    }
    long long **temp;
    new_matrix(temp);
    quick_pow(base, index >> 1, temp);
    multiply(temp, temp, res);
    if (index & 1)
    {
        for (int i = 0; i < MAXM; i ++)
            for (int j = 0; j < MAXM; j ++)
                temp[i][j] = res[i][j];
        multiply(temp, base, res);
    }
    delete_matrix(temp);
}
void solve(int x)
{
    long long **base, **res;
    new_matrix(base);
    new_matrix(res);
    for (int i = 0; i <= seg[x].c; i ++)
    {
        if (i > 0) base[i][i - 1] = 1;
        base[i][i] = 1;
        if (i < seg[x].c) base[i][i + 1] = 1;
    }
    quick_pow(base, seg[x].b - seg[x].a, res);
    /*for (int i = 0; i < MAXM; i ++)
    {
        for (int j = 0; j < MAXM; j ++)
            printf("%lld ", res[i][j]);
        printf("\n");
    }*/
    long long *temp = new long long[MAXM];
    for (int i = 0; i < MAXM; i ++)
    {
        temp[i] = 0;
        for (int j = 0; j < MAXM; j ++)
            temp[i] = (temp[i] + dp[j] * res[i][j]) % mod;
    }
    for (int i = 0; i < MAXM; i ++)
        dp[i] = temp[i];
    delete_matrix(base);
    delete_matrix(res);
    delete temp;
}
int main()
{
    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i ++)
        scanf("%lld%lld%d", &seg[i].a, &seg[i].b, &seg[i].c);
    seg[n].b = k;
    dp[0] = 1;
    for (int i = 1; i <= n; i ++)
        solve(i);
    printf("%lld", dp[0]);
    return 0;
}


#include <cstdio>
#include <algorithm>
#define mod 1000000007
const int MAXN = 105, MAXM = 16;
int n;
long long k;
long long dp[MAXM];
using namespace std;
struct Segment
{
    long long a, b;
    int c;
}seg[MAXN];
void new_matrix(long long** &matrix)
{
    matrix = new long long*[MAXM];
    for (int i = 0; i < MAXM; i ++)
    {
        matrix[i] = new long long[MAXM];
        for (int j = 0; j < MAXM; j ++)
            matrix[i][j] = 0;
    }
}
void delete_matrix(long long** matrix)
{
    for (int i = 0; i < MAXM; i ++)
        delete matrix[i];
    delete matrix;
}
void multiply(long long** a, long long** b, long long** c)
{
    for (int i = 0; i < MAXM; i ++)
        for (int j = 0; j < MAXM; j ++)
        {
            c[i][j] = 0;
            for (int k = 0; k < MAXM; k ++)
                c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % mod;
        }
}
void quick_pow(long long** base, long long index, long long** res)
{
    if (index == 1)
    {
        for (int i = 0; i < MAXM; i ++)
            for (int j = 0; j < MAXM; j ++)
                res[i][j] = base[i][j];
        return;
    }
    long long **temp;
    new_matrix(temp);
    quick_pow(base, index >> 1, temp);
    multiply(temp, temp, res);
    if (index & 1)
    {
        for (int i = 0; i < MAXM; i ++)
            for (int j = 0; j < MAXM; j ++)
                temp[i][j] = res[i][j];
        multiply(temp, base, res);
    }
    delete_matrix(temp);
}
void solve(int x)
{
    long long **base, **res;
    new_matrix(base);
    new_matrix(res);
    for (int i = 0; i <= seg[x].c; i ++)
    {
        if (i > 0) base[i][i - 1] = 1;
        base[i][i] = 1;
        if (i < seg[x].c) base[i][i + 1] = 1;
    }
    quick_pow(base, seg[x].b - seg[x].a, res);
    long long *temp = new long long[MAXM];
    for (int i = 0; i < MAXM; i ++)
    {
        temp[i] = 0;
        for (int j = 0; j < MAXM; j ++)
            temp[i] = (temp[i] + dp[j] * res[i][j]) % mod;
    }
    for (int i = 0; i < MAXM; i ++)
        dp[i] = temp[i];
    delete_matrix(base);
    delete_matrix(res);
    delete temp;
}
int main()
{
    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i ++)
        scanf("%lld%lld%d", &seg[i].a, &seg[i].b, &seg[i].c);
    seg[n].b = k;
    if (seg[n].a == seg[n].b) n--;
    dp[0] = 1;
    for (int i = 1; i <= n; i ++)
        solve(i);
    printf("%lld", dp[0]);
    return 0;
}


#include<set>
#include <unordered_set>
#include <unordered_map>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<math.h>
#include <string.h>
#include <strings.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define clr(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define readll(x) scanf("%I64d",&x)
#define mod 1000000007
#define eps 1e-10
#define infi  1000000000ll
#define infll 1000000000000000000ll

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef unordered_set<int> usi;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef unordered_map<ll,ll> umll;

int n;
ll k;
struct matrix {
    ll mat[16][16];
    int n,m;
    matrix(int n,int m) : n(n),m(m) {clr(mat, 0);}
    matrix(){}

    matrix operator * (const matrix &a) const {
        matrix ret (n,a.m);
        lp(i, 0, n-1) lp(j, 0, a.m-1) lp(k, 0, m-1) ret.mat[i][j] = (ret.mat[i][j]+1ll*mat[i][k]*a.mat[k][j]%mod)%mod;
        return ret;
    }
};

matrix power(const matrix &mat,ll p) {
    if(p == 1) return mat;
    matrix ret = power(mat, p>>1);
    ret = ret*ret;
    return p&1? ret*mat:ret;
}
void reset(matrix &trans,int c) {
    clr(trans.mat, 0);
    trans.mat[0][0] = trans.mat[0][1] = 1;
    if(c > 0) {
        trans.mat[c][c] = trans.mat[c][c-1] = 1;
        lp(i, 1, c-1) trans.mat[i][i] = trans.mat[i][i+1] = trans.mat[i][i-1] = 1;
    }
}

int main(){
    scanf("%d%lld",&n,&k);
    matrix ans(16,1);
    matrix trans (16,16);

    ans.mat[0][0] = 1;
    lp(i, 1, n) {
        ll a,b;
        int c;
        scanf("%lld%lld%d",&a,&b,&c);
        b = min(b, k);
        reset(trans,c);
        ans = power(trans, b-a)*ans;
    }

    printf("%lld\n",ans.mat[0][0]);
    return 0;
}

/*
 */

//ios::sync_with_stdio(0);cin.tie(0);


arr =[]
test_cases =int(input(''))
for x in range(test_cases):
    a=[]
    a = list(map(int,input().split()))
    arr.append(a)
for t in range(test_cases):
    x=arr[t][0]
    y=arr[t][1]
    a=arr[t][2]
    b=arr[t][3]

    if abs(y-x)%(a+b)==0:
        if abs(y-x)%(a+b)==0:
            print((y-x)/(a+b))
    else :
        print("-1")


arr =[]
test_cases =int(input(''))
for x in range(test_cases):
    a=[]
    a = list(map(int,input().split()))
    arr.append(a)
for t in range(test_cases):
    x=arr[t][0]
    y=arr[t][1]
    a=arr[t][2]
    b=arr[t][3]

    if abs(y-x)%(a+b)==0:
        if abs(y-x)%(a+b)==0:
            print (int((y-x)/(a+b)))
    else :
        print("-1")


arr =[]
test_cases =int(input(''))
for x in range(test_cases):
    a=[]
    a = list(map(int,input().split()))
    arr.append(a)
for t in range(test_cases):
    x=arr[t][0]
    y=arr[t][1]
    a=arr[t][2]
    b=arr[t][3]

    if abs(y-x)%(a+b)==0:
        if abs(y-x)%(a+b)==0:
            print int(((y-x)/(a+b)))
    else :
        print("-1")


x = int(input())
lst = []
for i in range(x):
    lst.append(input())
for i in lst:
    a = list(map(int,i.split()))
    distance = a[1]-a[0]
    foot = a[2]+a[3]
    if distance%foot!=0:
        print(-1)
    else:
        print(distance//foot)


x = int(input())
lst = []
for i in range(x):
    lst.append(input())
for i in lst:
    a.clear()
    a = i.split()
    distance = a[1]-a[0]
    foot = a[2]+a[3]
    if distance%foot!=0:
        print(str(-1))
    else:
        print(distance/foot)


x = int(input())
lst = []
for i in range(x):
    lst.append(input())
for i in lst:
    a.clear()
    a = i.split()
    distance = i[1]-i[0]
    foot = i[2]+i[3]
    if distance%foot!=0:
        print(str(-1))
    else:
        print(distance/foot)


t=int(input())
for i in range(t):
	x,y,a,b=map(int,input().split())
	count=0
	c=0
	while x<y:
		x=x+a
		y=y-b
		count=count+1
		if x==y:
			print(count)
			c=1
	if c==0:
		print("-1")


t=int(input())
for i in range(t):
	x,y,a,b=map(int,input().split())
	y=y-x
	if y%(a+b)==0:
		print(y//(a+b))
	else:
		print("-1")