import numpy as np N, M, K = map(int, input().split()) G = [[] for _ in range(N)] PQC = [tuple(map(int, input().split())) for _ in range(M)] MOD = 10 ** 9 + 7 dp = np.zeros((300, K + 1), dtype=np.object) dp[:, 0] = 1 for i in range(N - 1): new_dp = np.zeros_like(dp) for p, q, c in PQC: if c > K: continue new_dp[q - 1, c:] += dp[p - 1, :K + 1 - c] new_dp[q - 1] % MOD dp = new_dp print(dp[:, -1].sum() % MOD)