10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.  The _score_ of a participant is the product of his/her ranks in the two contests.  Process the following Q queries:    * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))


Q = ir()
answer = []
for _ in range(Q):
    a, b = lr()
    if a > b:
        a, b = b, a
    if a == b:
        ans = (a-1)*(b-1)
    elif b == a+1:
        if a == 1:
            ans = 0
        else:
            ans = b-1
    elif b > a + 1:
        c = int((a*b-1) ** .5)
        
        if c * (c+1) >= a * b:
            ans = 2 * c - 2
        else:
            ans = 2 * c - 1
    answer.append(ans)

print('\n'.join(map(str, answer)))


# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))


Q = ir()
answer = []
for _ in range(Q):
    a, b = lr()
    if a > b:
        a, b = b, a
    if a == b:
        ans = (a-1) * 2
    elif b == a+1:
        ans = 2 * (a-1)
    elif b > a + 1:
        c = int((a*b-1) ** .5) - 2
        while (c+1) ** 2 < a*b:
            c += 1
        
        if c * (c+1) >= a * b:
            ans = 2 * c - 2
        else:
            ans = 2 * c - 1
    answer.append(ans)

print('\n'.join(map(str, answer)))

