def solve(ab,i):

    return (ab - 1) // i

    

q = int(eval(input()))

for i in range(q):

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

    if a > b:

        a, b = b, a

    ans = a - 1

    

    start_a = a + 1

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

    while True:

        if solve(a*b, num) == solve(a*b, num + 1):

            break

        else:

            num += 1

    ans = num - 1

    ans += (solve(a*b, num) - 1)

    if a == b:

        ans += 1

    print(ans)





q = int(eval(input()))

info = [list(map(int, input().split())) for i in range(q)]



for i in range(q):

    min_, max_ = info[i]

    min_, max_ = min(min_, max_), max(min_, max_)

    

    # a, b = 1, 1 のときREが出る

    if min_ == 1 and max_ == 1:

        print((0))

        continue



    mul = min_ * max_

    ans = 2 * (min_ - 1)



    ok = 0

    ng = max_ + 10

    while abs(ok - ng) > 1:

        mid = (ok + ng) // 2

        if mid <= (mul - 1) // mid:

            ok = mid

        else:

            ng = mid

    ans += max(ok - (min_ - 1), 0)

    ans += max(ok - min_, 0)

    

    if ok == (mul - 1) // ok:

        ans -= 1

    print(ans)
def solve(ab, i):
    return (ab - 1) // i


q = int(eval(input()))
for i in range(q):
    a, b = list(map(int, input().split()))
    if a > b:
        a, b = b, a
    ans = a - 1
    start_a = a + 1
    num = int((a * b) ** 0.5)
    while True:
        if solve(a * b, num) == solve(a * b, num + 1):
            break
        else:
            num += 1
    ans = num - 1
    ans += solve(a * b, num) - 1
    if a == b:
        ans += 1
    print(ans)

q = int(eval(input()))
info = [list(map(int, input().split())) for i in range(q)]
for i in range(q):
    min_, max_ = info[i]
    min_, max_ = min(min_, max_), max(min_, max_)
    # a, b = 1, 1 のときREが出る
    if min_ == 1 and max_ == 1:
        print((0))
        continue
    mul = min_ * max_
    ans = 2 * (min_ - 1)
    ok = 0
    ng = max_ + 10
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if mid <= (mul - 1) // mid:
            ok = mid
        else:
            ng = mid
    ans += max(ok - (min_ - 1), 0)
    ans += max(ok - min_, 0)
    if ok == (mul - 1) // ok:
        ans -= 1
    print(ans)

-def solve(ab, i): -    return (ab - 1) // i - - +info = [list(map(int, input().split())) for i in range(q)] -    a, b = list(map(int, input().split())) -    if a > b: -        a, b = b, a -    ans = a - 1 -    start_a = a + 1 -    num = int((a * b) ** 0.5) -    while True: -        if solve(a * b, num) == solve(a * b, num + 1): -            break +    min_, max_ = info[i] +    min_, max_ = min(min_, max_), max(min_, max_) +    # a, b = 1, 1 のときREが出る +    if min_ == 1 and max_ == 1: +        print((0)) +        continue +    mul = min_ * max_ +    ans = 2 * (min_ - 1) +    ok = 0 +    ng = max_ + 10 +    while abs(ok - ng) > 1: +        mid = (ok + ng) // 2 +        if mid <= (mul - 1) // mid: +            ok = mid -            num += 1 -    ans = num - 1 -    ans += solve(a * b, num) - 1 -    if a == b: -        ans += 1 +            ng = mid +    ans += max(ok - (min_ - 1), 0) +    ans += max(ok - min_, 0) +    if ok == (mul - 1) // ok: +        ans -= 1