Buggy python submission (verdict: Runtime Error):
import sys

# import bisect

# from collections import Counter, deque, defaultdict

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    q = int(input())

    for i in range(q):
        a, b = list(map(int, readline().split()))
        if a > b:
            a, b = b, a

        if a == b or a + 1 == b:
            print(2 * a - 2)
        else:
            ab = a * b
            sqab = math.floor(math.sqrt(ab))

        if sqab * (sqab + 1) >= ab:
            print(2 * sqab - 2)
        else:
            print(2 * sqab - 1)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

import bisect

# from collections import Counter, deque, defaultdict

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    q = int(input())

    for i in range(q):
        a, b = list(map(int, readline().split()))

        if a > b:
            a, b = b, a

        if a == b or a + 1 == b:
            print(2 * a - 2)
        else:
            ab = a * b
            ok = 0
            ng = int(ab ** 0.5) + 1000000
            while abs(ng - ok) > 1:
                mid = (ok + ng) // 2
                if mid ** 2 < ab:
                    ok = mid
                else:
                    ng = mid
            c = ok

            if c * (c + 1) < ab:
                print(2 * c - 1)
            else:
                print(2 * c - 2)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys

import bisect

from collections import Counter, deque, defaultdict

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    q = int(input())

    for i in range(q):
        a, b = list(map(int, readline().split()))
        if a > b:
            a, b = b, a

        if a == b or a + 1 == b:
            print(2 * a - 2)
        else:
            ab = a * b
            sqab = math.floor(math.sqrt(ab))

        if sqab * (sqab + 1) >= ab:
            print(2 * sqab - 2)
        else:
            print(2 * sqab - 1)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

import bisect

# from collections import Counter, deque, defaultdict

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    q = int(input())

    for i in range(q):
        a, b = list(map(int, readline().split()))

        if a > b:
            a, b = b, a

        if a == b or a + 1 == b:
            print(2 * a - 2)
        else:
            ab = a * b
            ok = 0
            ng = int(ab ** 0.5) + 1000000
            while abs(ng - ok) > 1:
                mid = (ok + ng) // 2
                if mid ** 2 < ab:
                    ok = mid
                else:
                    ng = mid
            c = ok

            if c * (c + 1) < ab:
                print(2 * c - 1)
            else:
                print(2 * c - 2)


if __name__ == '__main__':
    main()