N, M, K = map(int, input().split()) code = [list() for _ in range(300)] for i in range(M): p, q, c = map(int, input().split()) code[p-1].append([q-1, c]) mod = 10**9+7 dp = [[[0]*(K+1) for _ in range(300)] for _ in range(N)] for i in range(N-1): if i == 0: for j in range(300): for nex, c in code[j]: if c <= K: dp[i+1][nex][c] += 1 else: for j in range(300): for k in range(K+1): if dp[i][j][k] > 0: for nex, c in code[j]: if k+c <= K: dp[i+1][nex][k+c] += dp[i][j][k] dp[i+1][nex][k+c] %= mod sm = 0 for i in range(300): sm += dp[-1][i][-1] sm %= mod print(sm)