import sys input=lambda: sys.stdin.readline().rstrip() n,m,k=map(int,input().split()) mod=10**9+7 PQ=[[int(i) for i in input().split()] for _ in range(m)] DP=[[[0]*(k+1) for i in range(301)] for j in range(n+1)] for p,q,c in PQ: if c<=k: DP[2][q][c]+=1 for i in range(2,n): for p,q,c in PQ: for j in range(k+1-c): DP[i+1][q][j+c]+=DP[i][p][j] if DP[i+1][q][j+c]>mod: DP[i+1][q][j+c]=DP[i+1][q][j+c]%mod ans=0 for i in range(301): ans=(ans+DP[n][i][k])%mod print(ans)