import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines mod = 10 ** 9 + 7 n, m, k = map(int, readline().split()) mm = map(int, read().split()) PQC = zip(mm, mm, mm) jisho = [{} for _ in range(300)] for p, q, c in PQC: p -= 1 q -= 1 jisho[p][q] = c # dp[i][j][k]: i番目まで前がjで、合計kとなる組み合わせ dp = [[[0] * (k + 1) for _ in range(300)] for _ in range(n)] for j in range(300): dp[0][j][0] = 1 for i in range(n - 1): for j in range(300): for a in range(k + 1): ni = i + 1 dic = jisho[j] for idx, val in dic.items(): if val + a > k: continue nj = idx na = val + a dp[ni][nj][na] += dp[i][j][a] dp[ni][nj][na] %= mod ans = 0 for j in range(300): ans += dp[-1][j][k] ans%=mod print(ans%mod)