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