#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> cost(300, vector(300, -1)); for (int i = 0; i < m; i++) { cin >> p.at(i) >> q.at(i) >> c.at(i); p.at(i)--; q.at(i)--; cost.at(p.at(i)).at(q.at(i)) = c.at(i); } 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 l = 0; l < 300; l++) { for (int comp = cost.at(j).at(l); comp <= k; comp++) { if (cost.at(j).at(l) >= 0) { dp.at(i).at(l).at(comp) += dp.at(i - 1).at(j).at(comp - cost.at(j).at(l)); 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; }