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=int) dp[:, 0] = 1 for i in range(N-1): new_dp = np.zeros_like(dp) for p, q, c in PQC: new_dp[q - 1, c:] += dp[p - 1, :K + 1 - c] dp = new_dp % MOD print(dp[:, -1].sum() % MOD)