#region Header #!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools from queue import PriorityQueue import bisect import heapq def input(): return sys.stdin.readline()[:-1] sys.setrecursionlimit(1000000) #endregion # _INPUT = """4 6 2 # 1 2 0 # 1 3 0 # 2 1 1 # 3 1 0 # 2 3 0 # 3 2 2 # """ # sys.stdin = io.StringIO(_INPUT) MOD = 1000000007 def main(): N, M, K = map(int, input().split()) P = [None for _ in range(M)] Q = [None for _ in range(M)] C = [None for _ in range(M)] for i in range(M): P[i], Q[i], C[i] = map(int, input().split()) P[i] -= 1 Q[i] -= 1 Kmax = 300 dp = [[0 for _ in range(Kmax+1)] for _ in range(300)] for j in range(300): dp[j][0] = 1 for i in range(N-1): dp1 = [[0 for _ in range(Kmax+1)] for _ in range(300)] for m in range(M): for k in range(Kmax+1): if k + C[m] <= Kmax: dp1[Q[m]][k+C[m]] = (dp1[Q[m]][k+C[m]] + dp[P[m]][k]) % MOD dp = dp1 n = 0 for j in range(300): n += dp[j][K] print(n % MOD) if __name__ == '__main__': main()