#include #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; int main() { int N, M, K; cin >> N >> M >> K; vi P(M), Q(M), C(M); rep(i, M) { cin >> P[i] >> Q[i] >> C[i]; P[i]--; Q[i]--; } const int MOD = 1000000007; const int MAX = 305; vector> dp(MAX, vector(MAX, vi(MAX))); rep(i, M) { dp[2][Q[i]][C[i]]++; } for (int i = 2; i < MAX - 1; i++) { for (int j = 0; j < MAX; j++) { for (int k = 0; k < MAX; k++) { for (int l = 0; l < M; l++) { if (j != P[l]) continue; if (k + C[l] >= MAX) continue; dp[i + 1][Q[l]][k + C[l]] += dp[i][j][k]; dp[i + 1][Q[l]][k + C[l]] %= MOD; } } } } int cnt = 0; rep(i, M) { cnt += dp[N][i][K]; cnt %= MOD; } cout << cnt << endl; }