import sys input = sys.stdin.readline N,M,K = map(int,input().split()) PQC = [tuple(map(int,input().split())) for i in range(M)] es = [[] for _ in range(300)] for p,q,c in PQC: p,q = p-1,q-1 es[p].append((q,c)) MOD = 10**9+7 dp = [[[0]*(K+1) for _ in range(300)] for _ in range(N)] for i in range(300): dp[0][i][0] = 1 st = set([(i,0) for i in range(300)]) for i in range(N-1): st2 = set() for p,c in st: for np,dc in es[p]: if c+dc > K: continue dp[i+1][np][c+dc] += dp[i][p][c] dp[i+1][np][c+dc] %= MOD st2.add((np,c+dc)) st = st2 print(sum(a[-1] for a in dp[-1]) % MOD)