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(N)]
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(N):
    pre[f(i, 0)] = 1

for i in range(N - 1):
    dp = [0] * (305 * 305)
    for j in range(N):
        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(N):
    ans += pre[f(i, K)]
    ans %= mod
print(ans)