main = do
  q <- readLn :: IO Int
  ab <- getContents >>= return . map (map read . words) . lines :: IO [[Integer]]

  
  mapM_ print $ map (\(a:b:_) -> 2 * (sqrt' (a*b)) - (if isSq (a*b) then 2 else 1) + (if a==b then 1 else 0) - 1 + (if sqrt' (a*b) * (sqrt' (a*b) + 1) < a*b then 1 else 0)) ab
 
  where
    sqrt' :: Integer -> Integer
    sqrt' n = floor $ sqrt (fromIntegral n)

    isSq n = (sqrt' n) ^ 2 == n
