local msq = math.sqrt
local mfl, mce, mmi = math.floor, math.ceil, math.min
local mma = math.max

local function getsqrt(al, bl)
  local min, max = al, bl + 1LL
  local dst = al * bl
  while 1LL < max - min do
    local mid = (min + max) / 2
    if mid * mid <= dst then
      min = mid
    else
      max = mid
    end
  end
  return min
end

local q = io.read("*n")
for iq = 1, q do
  local a, b = io.read("*n", "*n")
  local c = 0LL
  if b < a then a, b = b, a end
  local al, bl = 0LL + a, 0LL + b
  local dst = al * bl
  local sql = getsqrt(al, bl)
  if sql * sql == dst then
    if sql == al then
      c = 2LL * (sql - 1LL)
    else
      c = 2LL * (sql - 1LL) - 1LL
    end
  elseif sql * (sql + 1LL) < dst then
    c = 2LL * sql - 1LL
  else
    c = 2LL * (sql - 1LL)
  end
  local str = tostring(c):gsub("LL", "")
  print(str)
end
