import sys input=sys.stdin.readline n = int(input()) for i in range(n): a, b = map(int, input().split()) c = a * b d = a + b hi = 10 ** 18 lw = 0 while hi - lw > 1: mid = (hi + lw) // 2 if c * 4 < (mid ** 2 - d) ** 2: hi = mid else: lw = mid print(hi)