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 - sa - sb - sm - ss
  where
    m  = floor (sqrt (fromIntegral(a*b-1)))
    sa = if a <= m then 1 else 0
    sb = if b <= m then 1 else 0
    sm = if m*(m+1) >= a*b then 1 else 0
    ss = if m*m >= a*b then 1 else 0