import sys def input(): return sys.stdin.buffer.readline()[:-1] MAX = 10 MOD = 10**9+7 n, m, K = map(int, input().split()) dp = [[0 for _ in range(K+1)] for _ in range(MAX)] for i in range(MAX): dp[i][0] = 1 adj = [[] for _ in range(MAX)] for _ in range(m): p, q, c = map(int, input().split()) adj[p-1].append((q-1, c)) for _ in range(n-1): new = [[0 for _ in range(K+1)] for _ in range(MAX)] for p in range(MAX): for j in range(K+1): for q, c in adj[p]: if j+c <= K: new[q][j+c] += dp[p][j] new[q][j+c] %= MOD dp = new ans = 0 for p in range(MAX): ans += dp[p][K] ans %= MOD print(ans)