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

function ans(A,B)
  integer(16) A,B
  integer(16) ans
  integer(16) C,root
  c=a*b
  root=floor(sqrt(dble(c)))
  if(root**2==c)then
    if(a==b)then
      ans=2*(root-1)
    else
      ans=2*root-3
    end if
  else if(root*(root+1)<c)then
    ans=2*root-1
  else 
    ans=2*(root-1)
  endif
end function
end