use proconio::input; fn main() { input! { t: usize, } let output = (0..t) .map(|_| solve()) .map(|cost| cost.to_string()) .collect::>() .join("\n"); println!("{output}"); } fn solve() -> usize { input! { (a, b, c, x, y, z): (usize, usize, usize, usize, usize, usize), } let mut nodes = [(a, x), (b, y), (c, z)]; nodes.sort_unstable_by_key(|&(value, _)| value); let calc_cost = |pivot: usize| { let pivot_value = nodes[pivot].0; nodes .iter() .map(|&(value, cost)| pivot_value.abs_diff(value) * cost) .sum::() }; (0..3).map(calc_cost).min().unwrap() }