N,M,K = map(int,input().split()) l = [] MOD = 10**9+7 for _ in range(M): p,q,c = map(int,input().split()) l.append((p,q,c)) dp = [[[0 for _ in range(K+1)] for _ in range(301)] for _ in range(N+1)] for i in range(N): for j in range(M): p,q,c = l[j] for k in range(K+1-c): dp[i+1][q][k+c] = dp[i][p][k]+1 dp[i+1][q][k+c] %= MOD ans = 0 for i in range(301): ans += dp[N][i][K]//2 print(ans)