import java.util.*; public class Main { static ArrayList> list = new ArrayList<>(); static int[][][] dp; static final int MOD = 1000000007; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); for (int i = 0; i <= 300; i++) { list.add(new HashMap<>()); } for (int i = 0; i < m; i++) { int p = sc.nextInt(); int q = sc.nextInt(); int c = sc.nextInt(); list.get(q).put(p, c); } dp = new int[n][k + 1][301]; for (int[][] arr1 : dp) { for (int[] arr2 : arr1) { Arrays.fill(arr2, -1); } } int ans = 0; for (int i = 1; i <= 300; i++) { ans += dfw(n - 1, k, i); ans %= MOD; } System.out.println(ans); } static int dfw(int idx, int value, int code) { if (idx == 0 && value == 0) { return 1; } if (idx <= 0 || value < 0) { return 0; } if (dp[idx][value][code] >= 0) { return dp[idx][value][code]; } int ans = 0; for (Map.Entry entry : list.get(code).entrySet()) { ans += dfw(idx - 1, value - entry.getValue(), entry.getKey()); ans %= MOD; } dp[idx][value][code] = ans; return ans; } }