#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll MOD = 1000000007; ll dp[301][301][301]; int main() { int N, M, K; cin >> N >> M >> K; int P[M]; int Q[M]; int C[M]; memset(dp, 0, sizeof(dp)); for (int i = 0; i < M; ++i) { cin >> P[i] >> Q[i] >> C[i]; dp[2][Q[i]][C[i]]++; } for (int i = 2; i < N; ++i) { for (int j = 0; j < M; ++j) { for (int k = K - C[j]; k >= 0; --k) { int nk = k + C[j]; // fprintf(stderr, "i: %d, (%d -> %d) k: %d, cnt: %lld\n", i, P[j], Q[j], nk, dp[i][P[j]][k]); dp[i + 1][Q[j]][nk] += dp[i][P[j]][k]; dp[i + 1][Q[j]][nk] %= MOD; } } } ll ans = 0; for (int i = 0; i <= 300; ++i) { ans += dp[N][i][K]; ans %= MOD; } cout << ans << endl; return 0; }