fn main() { const MOD: usize = 1_000_000_007; let (n, m, k): (usize, usize, usize) = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap(), ) }; let (mut p, mut q, mut c) = (vec![], vec![], vec![]); for _ in 0..m { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); p.push(iter.next().unwrap().parse::().unwrap() - 1); q.push(iter.next().unwrap().parse::().unwrap() - 1); c.push(iter.next().unwrap().parse::().unwrap()); } let mut dp = vec![vec![vec![0; k + 1]; n]; n]; for i in 0..n { dp[0][i][0] = 1; } for i in 0..(n - 1) { for j in 0..m { for l in 0..=k { if l + c[j] > k { continue; } dp[i + 1][q[j]][l + c[j]] = { (dp[i + 1][q[j]][l + c[j]] + dp[i][p[j]][l]) % MOD }; } } } let mut ans = 0; for i in 0..n { ans = (ans + dp[n - 1][i][k]) % MOD; } println!("{}", ans); }