def check(a, b):

  if b < a:

    a, b = b, a

  if b - a <= 1:

    return 2 * a - 2

  d = a * b

  c, ng = a, b

  while ng - c > 1:

    mid = (ng + c) // 2

    if mid ** 2 < d:

      c = mid

    else:

      ng = mid

  return 2 * c - 1 - (c * (c + 1) >= a * b)



for _ in range(int(eval(input()))):

  print((check(*list(map(int, input().split())))))

from math import sqrt



eps = 10**-7



def check(a, b):

  if b < a:

    a, b = b, a

  if b - a <= 1:

    return 2 * a - 2

  c = int(sqrt(a*b) - eps)

  assert(c**2 < a*b <= (c+1)**2)

  return 2 * c - 1 - (c * (c + 1) >= a * b)



for _ in range(int(eval(input()))):

  print((check(*list(map(int, input().split())))))
def check(a, b):
    if b < a:
        a, b = b, a
    if b - a <= 1:
        return 2 * a - 2
    d = a * b
    c, ng = a, b
    while ng - c > 1:
        mid = (ng + c) // 2
        if mid**2 < d:
            c = mid
        else:
            ng = mid
    return 2 * c - 1 - (c * (c + 1) >= a * b)


for _ in range(int(eval(input()))):
    print((check(*list(map(int, input().split())))))

from math import sqrt

eps = 10**-7


def check(a, b):
    if b < a:
        a, b = b, a
    if b - a <= 1:
        return 2 * a - 2
    c = int(sqrt(a * b) - eps)
    assert c**2 < a * b <= (c + 1) ** 2
    return 2 * c - 1 - (c * (c + 1) >= a * b)


for _ in range(int(eval(input()))):
    print((check(*list(map(int, input().split())))))

+from math import sqrt + +eps = 10**-7 + + -    d = a * b -    c, ng = a, b -    while ng - c > 1: -        mid = (ng + c) // 2 -        if mid**2 < d: -            c = mid -        else: -            ng = mid +    c = int(sqrt(a * b) - eps) +    assert c**2 < a * b <= (c + 1) ** 2