N,M,K = map(int,input().split()) edge = [] for _ in range(M): p,q,c = map(int,input().split()) edge.append((p,q,c)) mod = 10 ** 9 + 7 C = 301 dp = [[0] * (K + 1) for _ in range(C)] for p,q,c in edge: if c <= K: dp[q][c] += 1 for _ in range(N - 2): nx = [[0] * (K + 1) for _ in range(C)] for p,q,c in edge: for i in range(K - c + 1): nx[q][i + c] += dp[p][i] for p in range(C): for i in range(K + 1): nx[p][i] %= mod dp = nx ans = 0 for p in range(C): ans += dp[p][-1] print(ans%mod)