local function getsqrt(a, b)
  local min, max = a, b + 1
  local dst = a * b
  while 1 < 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 = 0
  if b < a then a, b = b, a end
  local dst = a * b
  local sql = getsqrt(a, b)
  if sql * sql == dst then
    if sql == a then
      c = 2 * (sql - 1)
    else
      c = 2 * (sql - 1) - 1
    end
  elseif sql * (sql + 1) < dst then
    c = 2 * sql - 1
  else
    c = 2 * (sql - 1)
  end
  print(c)
end
