#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

const int mod = 1000000007;
ll R,R2,modash;
int logR;
ll MR(ll x){
    ll ret = (x + (((x&(R-1ll))*modash)&(R-1ll))*mod)>>(logR);
    return (ret>=mod ? ret-mod : ret);
}
int get_mod(ll x){return (int)MR(MR(x)*R2);}
void init(){
    R=1ll;logR=0;modash=0;
    while(R<mod){R<<=1;logR++;}
    R2=R*R%mod;
    int t=0,r=R,i=1;
    while(r>1){
        if((t&1)==0){t+=mod;modash+=i;}
        t>>=1;r>>=1;i<<=1;
    }
}

vector<vl> mul(vector<vl> a, vector<vl> b){
  int n = a.size();
  vector<vl> ret(n,vl(n,0));
  REP(k,n)REP(i,n)REP(j,n){
    ret[i][j] += get_mod(a[i][k]*b[k][j]);
    if(ret[i][j]>=mod) ret[i][j] -= mod;
  }
  return ret;
}

int main(){
  int n,k,c,t;
  scanf("%d%d%d%d",&n,&k,&c,&t);
  // ????§???????
  // 0?§???????1?§????...4?§????????£??????§??\?????????????????°t?????§?????¨?????????
  vector<vl> mat(5*n,vl(5*n,0));
  // ??????????§?
  REP(i,4){
    REP(j,n) mat[i*n+j][(i+1)*n+j] += 1;
  }
  // ?????????????§?
  REP(_,k){
    int a,b,tm;
    scanf("%d%d%d",&a,&b,&tm);
    // --a; --b;
    --tm;
    REP(i,n){
      int from;
      if(i<b) from = i+a-1;
      else if(i<b+a-1) from = i-b;
      else from = i;
      int to = i;
      mat[tm*n+to][from] += 1;
    }
  }
  // REP(po,5*n){
  //   DEBUG_VEC(mat[po]);
  // }
  // cout<<endl;
  init();
  // ?´????
  vector<vl> ans(5*n,vl(5*n,0));
  REP(i,5*n) ans[i][i]=1;
  while(t){
    if(t&1) ans = mul(ans,mat);
    mat = mul(mat,mat);
    t>>=1;
  }
  // DEBUG
  // REP(po,5*n){
  //   DEBUG_VEC(ans[po]);
  // }
  cout<<ans[0][c-1]<<endl;
  return 0;
}