use proconio::input; const INF: i64 = 2_000_000_000_000_000_000; const LIMIT: i64 = 60; fn pow_2(n: i64) -> i64 { 1 << n } fn solve(s_x: i64, s_y: i64, t_x: i64, t_y: i64) -> i64 { if s_y.max(t_y) >= LIMIT { return (s_y - t_y).abs(); } let mut ans = INF; for h in s_y.max(t_y)..=LIMIT { let dist_x = (s_x / pow_2(h) - t_x / pow_2(h)).abs(); let dist_y = (h - s_y) + (h - t_y); ans = ans.min(dist_x + dist_y); } ans } fn main() { input! { t: usize }; for _ in 0..t { input! { s_x: i64, s_y: i64, t_x: i64, t_y: i64 }; println!("{}", solve(s_x, s_y, t_x, t_y)); } }