const INF: usize = 1usize << 60; fn solve() -> usize { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let x = temp[0]; let a = temp[1]; if x == 0 { return a; } let mut ret = INF; for cnt in 1..=a { let rest = a % cnt; let k = a / cnt; let val = x * cnt + (cnt-rest) * k * k + rest * (k+1) * (k+1); ret = ret.min(val); } ret } fn main() { let mut t = String::new(); std::io::stdin().read_line(&mut t).ok(); let t: usize = t.trim().parse().unwrap(); let mut result = Vec::with_capacity(t); for _ in 0..t { result.push(solve()); } for &v in result.iter() { println!("{}", v); } }