let sqrt_int x = float_of_int x |> sqrt |> int_of_float

let solve a b =
  let c = sqrt_int (a * b - 1) in
  let f a b =
    if b-a <= 1 then 2*a - 2
    else if c * (c+1) >= a*b then 2*c - 2
    else 2*c - 1
  in f (min a b) (max a b)

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