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