n,m,K = map(int,input().split()) mod = 10**9+7 pqlen = 301 pqc = [[] for i in range(pqlen)] for i in range(m): p,q,c = map(int,input().split()) p -= 1 q -= 1 pqc[p].append([q,c]) dp = [[[0]*pqlen for i in range(K+1)] for j in range(n+1)] for i in range(pqlen): dp[0][0][i] = 1 for i in range(n-1): for j in range(K+1): for k in range(pqlen): for l in pqc[k]: p,c = l if j+c <= K: dp[i+1][j+c][p] += dp[i][j][k] dp[i+1][j+c][p] %= mod #print(dp) print((sum(dp[n-1][K]))%mod)