use std::io::*; 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 n: usize = itr.next().unwrap().parse().unwrap(); for _ in 0..n { let mut a: usize = itr.next().unwrap().parse().unwrap(); let b: usize = itr.next().unwrap().parse().unwrap(); let mut c: usize = itr.next().unwrap().parse().unwrap(); let mut x: usize = itr.next().unwrap().parse().unwrap(); let y: usize = itr.next().unwrap().parse().unwrap(); let mut z: usize = itr.next().unwrap().parse().unwrap(); let mut ans = 1 << 60; let mut cnt = 0; if (a, x) < (c, z) { std::mem::swap(&mut a, &mut c); std::mem::swap(&mut x, &mut z); } if a == c { c -= 1; cnt += z; } if c == 0 { println!("-1",); continue; } // b max if (b > a && b > c) || (a > b && c > b) { println!("{}", cnt); continue; } if c - 1 > 0 && b > c - 1 { ans = std::cmp::min(ans, cnt + (b - (c - 1)) * y); } let mut tmp = 0; if b - 1 > 0 && a > b - 1 { tmp += (a - (b - 1)) * x; if c == b - 1 { tmp += std::cmp::min(x, z); c -= 1; } if c != 0 { ans = std::cmp::min(ans, cnt + tmp); } } if ans != (1 << 60) { println!("{}", ans); } else { println!("-1",); } } }