q=int(eval(input()))

for _ in range(q):

  a,b=list(map(int,input().split()))

  if a>b:

    a,b=b,a

  if a==b:

    print((2*a-2))

  elif a==b+1:

    print((2*a-1))

  else:

    c=int((a*b)**0.5)

    if c*c==a*b:

      c-=1

    if c*(c+1)>=a*b:

      print((2*c-2))

    else:

      print((2*c-1))
q=int(eval(input()))

for _ in range(q):

  a,b=list(map(int,input().split()))

  if a>b:

    a,b=b,a

  if a==b:

    print((2*a-2))

  elif b==a+1:

    print((2*a-2))

  else:

    c=int((a*b)**0.5)-1

    while (c+1)*(c+1)<a*b:

      c+=1

    if c*(c+1)>=a*b:

      print((2*c-2))

    else:

      print((2*c-1))
q = int(eval(input()))
for _ in range(q):
    a, b = list(map(int, input().split()))
    if a > b:
        a, b = b, a
    if a == b:
        print((2 * a - 2))
    elif a == b + 1:
        print((2 * a - 1))
    else:
        c = int((a * b) ** 0.5)
        if c * c == a * b:
            c -= 1
        if c * (c + 1) >= a * b:
            print((2 * c - 2))
        else:
            print((2 * c - 1))

q = int(eval(input()))
for _ in range(q):
    a, b = list(map(int, input().split()))
    if a > b:
        a, b = b, a
    if a == b:
        print((2 * a - 2))
    elif b == a + 1:
        print((2 * a - 2))
    else:
        c = int((a * b) ** 0.5) - 1
        while (c + 1) * (c + 1) < a * b:
            c += 1
        if c * (c + 1) >= a * b:
            print((2 * c - 2))
        else:
            print((2 * c - 1))

-    elif a == b + 1: -        print((2 * a - 1)) +    elif b == a + 1: +        print((2 * a - 2)) -        c = int((a * b) ** 0.5) -        if c * c == a * b: -            c -= 1 +        c = int((a * b) ** 0.5) - 1 +        while (c + 1) * (c + 1) < a * b: +            c += 1