main = do
  n <- readLn
  inps <- mapM (const (fmap (map read . words) getLine)) [1..n]
  mapM_ (print . solve) inps

solve :: [Int] -> Int
solve [a,b] =
  2*m - sq - sameA - sameB
  where
    m = floor (sqrt (fromIntegral(a*b-1)))
    sq = if m*(m+1) <= a*b-1 then 0 else 1
    sameA = if a<=m then 1 else 0
    sameB = if b<=m then 1 else 0