let solve a b =
  let c = int_of_float (ceil @@ sqrt (float_of_int (a * b)) -. 1.) in
  if abs (a-b) <= 1 then 2 * (min a b) - 2
  else if c * (c+1) >= a*b then 2*c - 2
  else 2*c - 1

let () =
  Scanf.scanf "%d" @@ fun q ->
  Array.init q (fun _ -> Scanf.scanf " %d %d" solve)
  |> Array.iter (Printf.printf "%d\n")