let sqrt_int x = int_of_float (sqrt (float_of_int x))

let () =
  Scanf.scanf "%d" @@ fun q ->
  Array.init q begin fun _ -> Scanf.scanf " %d %d" @@ fun a b ->
    let a, b = min a b, max a b in
    let mul, hmul = a * b - 1, sqrt_int (a * b - 1) in
    let rec calc v x y =
      if min (mul / (x+1)) y <= hmul then v
      else calc (v+1) (x+1) (min (mul / (x+1)) y - 1)
    in (a-1) + min b hmul + calc 0 a b
  end |> Array.iter (Printf.printf "%d\n")
