integer Q
integer(16) A,B
integer(16) ans
read*,Q
do i=1,Q
  read*,A,B
  ans=solve(A,B)
  print"(i0)",ans
end do
contains

function solve(A,B)
  integer(16) A,B
  integer(16) solve
  integer(16) C,tmp
  if(A>B)then
    tmp=A
    A=B
    B=tmp
  endif
  
  if(A==B)then
    solve=2*A-2
    return
  endif
  if(A+1==B)then
    solve=2*A-2
    return
  endif
  C=floor(sqrt(dble(A*B)))
  if(C**2==A*B)C=C-1
  if(C*(C+1)>A*B)then
    solve=2*C-2
  else
    solve=2*C-1
  endif
end function
end