#include using namespace std; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define repr(i,n) for(int i = (int)(n); i >= 0; i--) #define all(v) v.begin(),v.end() typedef long long ll; int main(){ ll N,M,K; cin >> N >> M >> K; vector P(M); vector Q(M); vector C(M); rep(i,M){ cin >> P[i] >> Q[i] >> C[i]; } ll dp[302][302][N + 1]; rep(i,302){ rep(j,302){ rep(k,N + 1){ dp[i][j][k] = 0; } } } for (ll i = 1; i <= 300; i++){ dp[0][i][0] = 1; } rep(i,N - 1){ rep(j,M){ for (ll k = 300; k >= 0; k--){ if (k + C[j] <= 300){ dp[k + C[j]][Q[j]][i + 1] = (dp[k + C[j]][Q[j]][i + 1] + dp[k][P[j]][i]) % 1000000007; } } } } ll ans = 0; for (ll i = 1; i <= 300; i++){ ans = (ans + dp[K][i][N - 1]) % 1000000007; } cout << ans << endl; }