Q=io.read("n")
for i=1,Q do
  A=io.read("n")
  B=io.read("n")
  if A>b then
    A,B=B,A
  end
  local count=0
  local k=1
  for i=B-1,A,-1 do
    if i*(A+k)<A*B then
      count=count+1
      k=k+1
    end
  end
  print(A*2+count-2)
end