from math import sqrt

q = int(eval(input()))

for _ in range(q):

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

    c = a * b

    d = int(sqrt(c))

    answer = 2 * d - 2

    if d**2 == c:

        answer -= 1

    if d * (d + 1) < c:

        answer += 1

    if a == b:

        answer += 1

    print(answer)
from math import sqrt

q = int(eval(input()))

for _ in range(q):

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

    c = a * b

    d = int(sqrt(c))

    answer = 2 * d - 2

    if d * d == c:

        answer -= 1

    if d * (d + 1) < c:

        answer += 1

    if a == b:

        answer += 1

    print(answer)
from math import sqrt

q = int(eval(input()))
for _ in range(q):
    a, b = list(map(int, input().split(" ")))
    c = a * b
    d = int(sqrt(c))
    answer = 2 * d - 2
    if d**2 == c:
        answer -= 1
    if d * (d + 1) < c:
        answer += 1
    if a == b:
        answer += 1
    print(answer)

from math import sqrt

q = int(eval(input()))
for _ in range(q):
    a, b = list(map(int, input().split(" ")))
    c = a * b
    d = int(sqrt(c))
    answer = 2 * d - 2
    if d * d == c:
        answer -= 1
    if d * (d + 1) < c:
        answer += 1
    if a == b:
        answer += 1
    print(answer)

-    if d**2 == c: +    if d * d == c: