N = int(input()) for i in range(N): a, b = map(int, input().split()) ok = 10 ** 18 ng = 2 left = 4 * a * b while ng + 1 < ok: mid = (ok + ng) // 2 mid_squared = mid * mid subright = mid_squared - a - b if subright <= 0: ng = mid else: right = subright * subright if left < right: ok = mid else: ng = mid print(ok)