let q = read_int ()

let rec f i =
  if i < q then (
    Scanf.scanf "%d %d\n" (fun a b ->
      let pro = a * b in
      let root = int_of_float (sqrt (float_of_int pro)) in
      let b = pro = root * root && a <> b in
      let ans = root + (pro - 1) / (root + 1) - 1 in
      let ans = ans + if b then -1 else 0 in
      Printf.printf "%d\n" ans;
      f (i + 1)
    )
  )

let () = f 0
