#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("YES");}else{puts("NO");} #define MAX_N 200005 int main() { int n, m, K; cin >> n >> m >> K; int p[m], q[m], c[m]; rep(i,m) cin >> p[i] >> q[i] >> c[i]; int dp[n][301][K+1]; rep(i,n)rep(j,301)rep(k,K+1)dp[i][j][k] = 0; rep(j,301) dp[0][j][0] = 1; ll MOD = 1000000007; rep(i,n-1){ rep(j,m){ rep(k,K+1){ if(k+c[j]>K)break; dp[i+1][q[j]][k+c[j]] += dp[i][p[j]][k]; dp[i+1][q[j]][k+c[j]] %= MOD; } } } ll ans = 0; rep(j,301){ ans += dp[n-1][j][K]; ans %= MOD; } cout << ans << endl; return 0; }