use std::cmp::max; use std::io; use std::io::{Write, BufRead}; pub fn main(){ let mut INPUT = io::BufReader::new(io::stdin().lock()).lines().map(Result::unwrap); let mut OUTPUT = io::BufWriter::new(io::stdout().lock()); let test_cases:u32 = INPUT.next().unwrap().parse().unwrap(); for _ in 0..test_cases{ let inp = INPUT.next().unwrap(); let mut inpit = inp.split_ascii_whitespace(); let a:u32 = inpit.next().unwrap().parse().unwrap(); let b:u32 = inpit.next().unwrap().parse().unwrap(); let mut x = None; if a == b{x = Some(0);} for k in 2..=b/a { if (b-k*a) % (k-1) == 0{ x = Some((b-k*a) / (k-1)) } } match x { None => writeln!(OUTPUT, "-1").unwrap(), Some(x) => writeln!(OUTPUT, "{}", x).unwrap() } } }