def solve(A, B): left = 0 right = 10 ** 9 + 2 while right - left > 1: mid = (left + right) // 2 if 4 * A * B < (mid ** 2 - A - B) ** 2: right = mid else: left = mid return right N = int(input()) for _ in range(N): A, B = [int(x) for x in input().split()] print(solve(A, B))