def solve(a, b): l = 1 r = 1 << 30 while r-l > 1: mid = (l+r)//2 if mid**2 - a - b > 0 and 4*a*b < (mid**2 - a - b)**2: r = mid else: l = mid return r N = int(input()) ans = [] for _ in range(N): A, B = map(int, input().split()) ans.append(solve(A, B)) print(*ans, sep="\n")