n = int(input()) def solve(): a, b = map(int, input().split()) # sqrt(a) + sqrt(b) < x # 2 * sqrt(ab) < (x^2-a-b) # 4ab < (x^2 - a - b) ^ 2 l = 0 r = 10**10 for i in range(100): m = (l + r) // 2 val = m**2-a-b if val < 0 or 4*a*b >= val**2: l = m else: r = m print(r) for i in range(n): solve()