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 ans = 1 << 60; let mut cnt = 0; if a < c { std::mem::swap(&mut a, &mut c); } if a == c { c -= 1; cnt += 1; } if c == 0 { println!("-1",); continue; } // b max if (b > a && b > c) || (a > b && c > b) { println!("{}", cnt); continue; } if c - 1 > 0 { ans = std::cmp::min(ans, cnt + (b - (c - 1))); } let mut tmp = 0; if b - 1 > 0 { tmp += a - (b - 1); if c == b - 1 { tmp += 1; c -= 1; } if c != 0 { ans = std::cmp::min(ans, cnt + tmp); } } if ans != (1 << 60) { println!("{}", ans); } else { println!("-1",); } } }