#include using namespace std; #define rep(i, n) for(int i = 0; i < (int)n; ++i) #define FOR(i, a, b) for(int i = a; i < (int)b; ++i) #define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i) using ll = long long; using ld = long double; const ll INF = 1e18; const int Inf = 1e9; const double EPS = 1e-9; const ll MOD = 1e9 + 7; const int N = 301; int main() { cin.tie(nullptr); ios::sync_with_stdio(0); int n, m, K; cin >> n >> m >> K; vector > code[N]; ll dp[n][N][N] = {}; rep(i, N) dp[0][i][0] = 1; rep(i, m) { int p, q, c; cin >> p >> q >> c; code[p - 1].emplace_back(q - 1, c); } rep(i, n - 1) { rep(j, N) { if (code[j].size() == 0) continue; rep(k, N) { rep(l, code[j].size()) { int next = code[j][l].first, comp = code[j][l].second; if (k + comp >= N) continue; dp[i + 1][next][k + comp] += dp[i][j][k]; dp[i + 1][next][k + comp] %= MOD; } } } } ll res = 0; rep(i, N) { res += dp[n - 1][i][K]; res %= MOD; } cout << res << endl; return 0; }