{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad (replicateM)
import           Data.Int      (Int64)

main :: IO ()
main = do
  q <- readLn
  abs <- replicateM q readInt2
  putStr . unlines . map show $ solve abs

solve :: [(Int64, Int64)] -> [Int64]
solve = map solve'

solve' :: (Int64, Int64) -> Int64
solve' (a, b)
  | a == b || a + 1 == b = 2 * a - 2
  | c * (c + 1) >= a * b = 2 * c - 2
  | otherwise            = 2 * c - 1
  where c = calcC a b

calcC :: Int64 -> Int64 -> Int64
calcC a b = if c * c == a * b then c - 1 else c
  where c = floor . sqrt . fromIntegral $ a * b

readInt2 :: IO (Int64, Int64)
readInt2 = do
  [a, b] <- map read . words <$> getLine
  return (a, b)
