#include using namespace std; int main() { const long mod = 1000000007; int n, m, k; cin >> n >> m >> k; assert(2 <= n && n <= 300); assert(1 <= m && m <= 300); assert(0 <= k && k <= 300); vector p(m), q(m), c(m); vector> check; for (int i = 0; i < m; i++) { cin >> p.at(i) >> q.at(i) >> c.at(i); assert(1 <= p.at(i) && p.at(i) <= 300); assert(1 <= q.at(i) && q.at(i) <= 300); assert(p.at(i) != q.at(i)); assert(0 <= c.at(i) && c.at(i) <= 300); check.emplace_back(p.at(i), q.at(i)); } sort(check.begin(), check.end()); for (int i = 0; i < m - 1; i++) { assert(check.at(i) != check.at(i + 1)); } for (int i = 0; i < m; i++) { p.at(i)--; q.at(i)--; } vector>> dp(n - 1, vector>(300, vector(k + 1))); for (int i = 0; i < m; i++) { dp.at(0).at(q.at(i)).at(c.at(i))++; } for (int i = 1; i < n - 1; i++) { for (int j = 0; j < m; j++) { for (int comp = c.at(j); comp <= k; comp++) { dp.at(i).at(q.at(j)).at(comp) += dp.at(i - 1).at(p.at(j)).at(comp - c.at(j)); dp.at(i).at(q.at(j)).at(comp) %= mod; } } } long ans = 0; for (int i = 0; i < 300; i++) { ans += dp.at(n - 2).at(i).at(k); ans %= mod; } cout << ans << endl; }