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 subright = (mid * mid - a - b) right = subright ** 2 if left < right: ok = mid else: ng = mid print(ok)