import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Debug.Trace 

main :: IO ()
main = readLn >>= readContents >>= mapM_ print . solve 

solve :: [[Int]] -> [Int]
solve = map calc 

calc :: [Int] -> Int
calc [a, b] = trace ("(m,v,d,s,ex)=" ++ show (m,v,d,s,ex)) v * 2 - d - s
    where
        m = a * b - 1
        v = truncate . sqrt $ fromIntegral m
        d
            | a <= v && b <= v = 2
            | a <= v || b <= v = 1
            | otherwise = 0
        s
            | ex <= fromIntegral v = 1
            | otherwise = 0
        ex = (sqrt (1 + 4 * fromIntegral m) - 1) / 2

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine