MOD=10**9+7 n=300 N,M,K=map(int,input().split()) P=[0]*M Q=[0]*M C=[0]*M for i in range(M): P[i],Q[i],C[i]=map(int,input().split()) P[i]-=1 Q[i]-=1 dp0=[[0]*(K+1) for i in range(n)] dp1=[[0]*(K+1) for i in range(n)] for i in range(n): dp0[i][0]=1 for t in range(N-1): for i in range(M): for num in range(K+1): nnum=num+C[i] if nnum>K: continue if t%2==0: dp1[Q[i]][nnum]+=dp0[P[i]][num] if dp1[Q[i]][num]>=MOD: dp1[Q[i]][nnum]-=MOD else: dp0[Q[i]][nnum]+=dp1[P[i]][num] if dp0[Q[i]][nnum]>=MOD: dp0[Q[i]][nnum]-=MOD if t%2==0: dp0=[[0]*(K+1) for i in range(n)] else: dp1=[[0]*(K+1) for i in range(n)] ans=0 for i in range(n): ans=(ans+dp0[i][K]+dp1[i][K])%MOD print(ans)