import sys input = sys.stdin.readline N, M, K = map(int, input().split()) PQR = [tuple(map(int, input().split())) for _ in range(M)] dp = [[[0]*(K+1) for _ in range(300)] for _ in range(N)] for i in range(300): dp[0][i][0] = 1 MOD = 10**9+7 for i in range(N-1): for j in range(K+1): for P, Q, R in PQR: if j+R<=K: dp[i+1][Q-1][j+R] += dp[i][P-1][j] dp[i+1][Q-1][j+R] %= MOD print(sum(dp[N-1][i][K] for i in range(300))%MOD)