Scanf.scanf "%d" (fun q ->
    for i = 1 to q do
        Scanf.scanf " %d %d" (fun a b ->
            let f = int_of_float (sqrt (float (a * b))) in
            let f = if f * f = a * b then f - 1 else f in
            let ax = if a <= f then f - 1 else f in
            let bx = if b <= f then f - 1 else f in
            let ans = if (a * b - 1) / f = f then ax + bx - 1 else ax + bx in

            Printf.printf "%d\n" ans
        )
    done
)