def issatisfy(m, a, b) -> bool: s = m**2 - (a + b) if s <= 0: return False x = 4 * a * b y = s ** 2 return x < y # INF = 1 << 60 INF = 10 ** 5 N = int(input()) for _ in range(N): A, B = map(int, input().split()) lo = 1 hi = INF ans = INF while lo <= hi: m = (lo + hi) // 2 if issatisfy(m, A, B): ans = min(ans, m) hi = m - 1 else: lo = m + 1 print(ans)