import sys import numpy as np 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()) m = map(int, read().split()) PQC = tuple(zip(m, m, m)) dp = np.zeros((310, 310), np.int64) # 最後の音、複雑度 -> 何通り # 1音目 dp[1:301, 0] = 1 for _ in range(N - 1): newdp = np.zeros_like(dp) for p, q, c in PQC: newdp[q, c:310] += dp[p, 0:310 - c] dp = newdp % MOD ans = dp[:, K].sum() % MOD print(ans)