test_solver::Int->Int->Int
test_solver x y = if x == y then (x-1)*2
                            else let a = max x y in
                                 let b = min x y in
                                 let n' = floor (sqrt (fromIntegral (a*b))) in
                                 let n  = if n'*n'>= a*b then (n'-1) else n' in
                                 if n*(n+1) < a*b then (((n-b)*2)+1) + ((b-1)*2)
                                                  else ((n-b)*2) + ((b-1)*2)

n_do::Int->IO()
n_do 0 = return ()
n_do n = do
  abc<-getLine
  let a:b:[]=map read (words abc)
  print (test_solver a b)
  n_do (n-1)


main::IO()
main=do
  nc<-getLine
  let n = read nc ::Int
  n_do n
