use std::io::*; const MOD: i64 = 1_000_000_007; fn ext_gcd(a: i64, b: i64, x: &mut i64, y: &mut i64) -> i64 { if b == 0 { *x = 1; *y = 0; a } else { let d = ext_gcd(b, a % b, y, x); *y -= (a / b) * *x; d } } fn calc(a: i64, b: i64, c: i64, y: i64) -> i64 { let mut ans = 0; for i in 0..=y / a { let d = y - i * a; // d = b * x + c * y let mut x0 = 0; let mut y0 = 0; let g = ext_gcd(b, c, &mut x0, &mut y0); if d % g != 0 { continue; } x0 *= d / g; y0 *= d / g; let bs = b / g; let cs = c / g; let u = (-y0 + bs - 1) / bs; x0 -= u * cs; if x0 >= 0 { ans = (ans + (x0 / cs + 1) % MOD) % MOD } } ans } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let t: usize = itr.next().unwrap().parse().unwrap(); for _ in 0..t { let mut a = vec![0; 3]; a[0] = itr.next().unwrap().parse().unwrap(); a[1] = itr.next().unwrap().parse().unwrap(); a[2] = itr.next().unwrap().parse().unwrap(); let y: i64 = itr.next().unwrap().parse().unwrap(); a.sort_by_key(|x| -x); println!("{}", calc(a[0], a[1], a[2], y)); } }