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-1) (if mul/hmul = a then hmul-1 else hmul) + calc 0 a (a*b)
  end |> Array.iter (Printf.printf "%d\n")
