mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N, M, K = map(int, input().split()) dp = [[0] * (K+1) for _ in range(301)] for p in range(1, 301): dp[p][0] = 1 code = [] for _ in range(M): code.append(tuple(map(int, input().split()))) for _ in range(N-1): dp_new = [[0] * (K+1) for _ in range(301)] for p, q, c in code: for k in range(K+1): if k + c <= K: dp_new[q][k+c] = (dp_new[q][k+c] + dp[p][k])%mod dp = dp_new ans = 0 for q in range(1, 301): ans = (ans + dp[q][K])%mod print(ans) if __name__ == '__main__': main()