#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long dp[330][330][630]; long long p[330], q[330], c[330]; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= m; i++) { cin >> p[i] >> q[i] >> c[i]; } for (int i = 1; i <= 300; i++) { dp[0][i][0] = 1; } for (int i = 1; i < n; i++) { for (int j = 1; j <= m; j++) { for (int l = 0; l <= k; l++) { dp[i][q[j]][l + c[j]] += dp[i - 1][p[j]][l]; dp[i][q[j]][l + c[j]] %= 1000000007; } } } long long ans = 0; for (int i = 0; i <= 300; i++) { ans += dp[n - 1][i][k]; ans %= 1000000007; } cout << ans << endl; return 0; }