#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


typedef vector<ll> V;
typedef vector<V> MATRIX;

int SIZE;
int base[40],work[40],next_loc[40];

MATRIX calc(MATRIX left,MATRIX right){

	MATRIX ret(SIZE,V(SIZE));

	for(int i = 0; i < SIZE; i++){
		for(int k = 0; k < SIZE; k++)ret[i][k] = 0;
	}

	for(int row = 0; row < SIZE; row++){
		for(int col = 0; col < SIZE; col++){
			for(int a = 0; a < SIZE; a++){
				ret[row][col] += left[row][a]*right[a][col]%MOD;
				ret[row][col] %= MOD;
			}
		}
	}

	return ret;
}


MATRIX pow(MATRIX MULT,int count){

	MATRIX ret(SIZE,V(SIZE));

	for(int row = 0; row < SIZE; row++){
		for(int col = 0; col < SIZE; col++){
			if(row == col)ret[row][col] = 1;
			else{
				ret[row][col] = 0;
			}
		}
	}

	while(count > 0){
		if(count%2 == 1)ret = calc(ret,MULT);
		MULT = calc(MULT,MULT);
		count /= 2;
	}

	return ret;
}


int main(){

	int N,K,C,T;
	scanf("%d %d %d %d",&N,&K,&C,&T);
	C--;

	for(int i = 0; i < N; i++)base[i] = i;

	SIZE = 5*N;

	MATRIX MULT(SIZE,V(SIZE));
	for(int row = 0; row < SIZE; row++){
		for(int col = 0; col < SIZE; col++)MULT[row][col] = 0;
	}

	int from,num,add_time;
	int work_index,base_row = 0,base_col;

	for(int loop = 0; loop < K; loop++){
		scanf("%d %d %d",&from,&num,&add_time);
		from--;

		work_index = 0;
		for(int i = 0;i < num; i++){
			work[work_index++] = base[from+i];
		}

		for(int i = 0; i < N; i++){
			if(i >= from && i <= from+num-1)continue;
			work[work_index++] = base[i];
		}

		base_col = N*(add_time-1);
		for(int i = 0; i < N; i++){
			MULT[base_row+work[i]][base_col+i]++;
		}
	}

	for(base_row = N; base_row <= 4*N; base_row += N){
		for(base_col = 0; base_col <= 4*N; base_col += N){
			if(base_row-N != base_col)continue;
			for(int i = 0; i < N; i++)MULT[base_row+i][base_col+i] = 1;
		}
	}

	MULT = pow(MULT,T);

	printf("%lld\n",MULT[C][0]%MOD);

	return 0;
}

