import sys input = sys.stdin.readline mod=10**9+7 N,M,K=map(int,input().split()) E=[[] for i in range(301)] for i in range(M): p,q,c=map(int,input().split()) E[p].append((q,c)) DP=dict() for i in range(1,301): DP[(i,0)]=1 for i in range(N-1): NDP=dict() for i,now in DP: for to,cost in E[i]: if now+cost<=K: if (to,now+cost) in NDP: NDP[to,now+cost]+=DP[i,now] NDP[to,now+cost]%=mod else: NDP[to,now+cost]=DP[i,now] DP=NDP ANS=0 for i,c in DP: if c==K: ANS=(ANS+DP[i,c])%mod print(ANS)