""" グラフ メモ化再帰 各頂点で開始、複雑さXのものはいくつあるかをメモ化再帰で求める N * 300 なので行ける """ import sys mod = 10**9+7 def dfs(v,k,n): if k == 0 and n == 0: return 1 elif k < 0 or n <= 0: return 0 elif visit[v][k][n] != None: return visit[v][k][n] ret = 0 for nex,cost in lis[v]: ret += dfs(nex , k-cost , n-1) ret %= mod visit[v][k][n] = ret return ret N,M,K = map(int,input().split()) lis = [ [] for i in range(N) ] visit = [[[None] * N for j in range(K+1)] for i in range(N)] for i in range(M): P,Q,C = map(int,input().split()) P -= 1 Q -= 1 lis[P].append((Q,C)) ans = 0 for i in range(N): ans += dfs(i,K,N-1) ans %= mod print (ans) #print (visit)