def f(p, c): return p * (K + 2) + c N, M, K = map(int, input().split()) mod = 10 ** 9 + 7 G = [[] for i in range(305)] for i in range(M): P, Q, C = map(int, input().split()) P, Q = P - 1, Q - 1 G[P].append((Q, C)) pre = [0] * (305 * 305) for i in range(301): pre[f(i, 0)] = 1 for i in range(N - 1): dp = [0] * (305 * 305) for j in range(301): for c in range(K + 2): for u, C in G[j]: dp[f(u, min(K + 1, c + C))] += pre[f(j, c)] dp[f(u, min(K + 1, c + C))] %= mod dp, pre = pre, dp ans = 0 for i in range(301): ans += pre[f(i, K)] ans %= mod print(ans)