fn main() { let mut nmk = String::new(); std::io::stdin().read_line(&mut nmk).ok(); let nmk: Vec = nmk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nmk[0]; let m = nmk[1]; let k = nmk[2]; let mut progress: Vec> = vec![vec![]; 300]; for _ in 0..m { let mut pqc = String::new(); std::io::stdin().read_line(&mut pqc).ok(); let pqc: Vec = pqc.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); progress[pqc[0] - 1].push((pqc[1] - 1, pqc[2])); } const DIVISOR: usize = 1e9 as usize + 7usize; let mut dp: Vec>> = vec![vec![vec![0; 300]; k+1]; n]; for i in 0..300 { dp[0][0][i] = 1; } for i in 1..n { for c in 0..=k { for m in 0..300 { if dp[i-1][c][m] == 0 { continue; } progress[m].iter() .filter(|&pair| pair.1 + c <= k) .for_each(|&pair| { dp[i][c + pair.1][pair.0] += dp[i-1][c][m]; dp[i][c + pair.1][pair.0] %= DIVISOR; }); } } } println!("{}", dp[n-1][k].iter().sum::() % DIVISOR); }