#include using namespace std; int main() { const long mod = 1000000007; int n, m, k; cin >> n >> m >> k; vector p(m), q(m), c(m); vector> ac(300, vector(300)); for (int i = 0; i < m; i++) { cin >> p.at(i) >> q.at(i) >> c.at(i); p.at(i)--; q.at(i)--; ac.at(p.at(i)).at(q.at(i)) = true; } vector>> dp(n - 1, vector>(300, vector(k + 1))); for (int i = 0; i < m; i++) { if (c.at(i) <= k) dp.at(0).at(q.at(i)).at(c.at(i))++; } for (int i = 1; i < n - 1; i++) { for (int j = 0; j < 300; j++) { for (int comp = c.at(j); comp <= k; comp++) { for (int l = 0; l < 300; l++) { if (ac.at(j).at(l)) { dp.at(i).at(l).at(comp) += dp.at(i - 1).at(j).at(comp - c.at(j)); dp.at(i).at(l).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; }