import Control.Monad

main=do
  q<-readLn::IO Int
  abs<-replicateM q $ map read.words<$> getLine::IO[[Int]]
  --
  putStr.unlines.map show.map solve $ abs
--
solve (a:b:_)
  | a > b = solve [b,a]
  | a==b = (a-1)*2
  | a+1==b = (a-1)*2
  | True = f (a*b)
--
f n
  | c*c+c >= n = (c-1)*2
  | True = c*2-1
  where c = g n
g n
  | sq*sq < n = sq
  | True = sq-1
  where sq = truncate.sqrt.fromIntegral $ n