for _ in range(int(input())): a, b = map(int, input().split()) l = 0 r = 63246 S = a + b T = 4 * a * b while r - l > 1: x = (l + r) // 2 x2 = x * x if x2 >= S and T < (x2 - S) ** 2: r = x else: l = x print(r)