#include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int P = 1000000007; struct X { int p, q, c; }; int main() { int dp[2][300][301] = {}; X x[300]; int n, m, k; cin >> n >> m >> k; for (int j = 0; j < m; j++) { int p, q, c; cin >> p >> q >> c; p--; q--; x[j] = { p, q, c }; } for (int l = 0; l < 300; l++) { dp[0][l][0] = 1; } for (int i = 1; i < n; i++) { for (int j = 0; j < m; j++) { auto [p, q, c] = x[j]; for (int h = c; h <= k; h++) { auto &t = dp[1][q][h]; t += dp[0][p][h - c]; if (t >= P) t -= P; } } for (int l = 0; l < 300; l++) { for (int h = 0; h <= k; h++) { dp[0][l][h] = dp[1][l][h]; dp[1][l][h] = 0; } } } ll r = 0; for (int l = 0; l < 300; l++) { r += dp[0][l][k]; } cout << r % P << endl; return 0; }