import Data.List
import Control.Monad

main = do
  q <- readLn
  replicateM_ q solve

solve :: IO ()
solve = do
  [a, b] <- sort . map read . words <$> getLine :: IO [Integer]
  print $ case () of 
            _
              | a == b -> 2*a - 2
              | a+1 == b -> 2*a - 2
              | otherwise ->
                let
                  c = floor $ sqrt $ fromIntegral (a*b)
                in
                  if c*(c+1) >= a*b
                    then 2*c - 2
                    else 2*c - 1