from math import sqrt

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

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

    if not a < b:

        a, b = b, a

    ans = (a-1)*2 + (a < b-1)

    c = int(sqrt(a*b))

    if c**2 == a*b:

        c -= 1

    if a < c:

        if (a*b) % c == 0:

            d = (a*b)//c - 1

        else:

            d = a*b//c

        ans += (c - a) * 2 - (c==d)

    print(ans)





# seishin.py

from math import sqrt

Q = int(eval(input()))

for i in range(Q):

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

    if not a < b:

        a, b = b, a

    if a == b or a+1 == b:

        print((2*a-2))

        continue

    c = int(sqrt(a*b))

    if c**2 == a*b:

        c -= 1

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

        print((2*c-2))

        continue

    print((2*c-1))
from math import sqrt

for i in range(int(eval(input()))):
    a, b = list(map(int, input().split()))
    if not a < b:
        a, b = b, a
    ans = (a - 1) * 2 + (a < b - 1)
    c = int(sqrt(a * b))
    if c**2 == a * b:
        c -= 1
    if a < c:
        if (a * b) % c == 0:
            d = (a * b) // c - 1
        else:
            d = a * b // c
        ans += (c - a) * 2 - (c == d)
    print(ans)

# seishin.py
from math import sqrt

Q = int(eval(input()))
for i in range(Q):
    a, b = list(map(int, input().split()))
    if not a < b:
        a, b = b, a
    if a == b or a + 1 == b:
        print((2 * a - 2))
        continue
    c = int(sqrt(a * b))
    if c**2 == a * b:
        c -= 1
    if c * (c + 1) >= a * b:
        print((2 * c - 2))
        continue
    print((2 * c - 1))

+# seishin.py -for i in range(int(eval(input()))): +Q = int(eval(input())) +for i in range(Q): -    ans = (a - 1) * 2 + (a < b - 1) +    if a == b or a + 1 == b: +        print((2 * a - 2)) +        continue -    if a < c: -        if (a * b) % c == 0: -            d = (a * b) // c - 1 -        else: -            d = a * b // c -        ans += (c - a) * 2 - (c == d) -    print(ans) +    if c * (c + 1) >= a * b: +        print((2 * c - 2)) +        continue +    print((2 * c - 1))