def main(): N = int(input()) for _ in range(N): A, B = map(int, input().split()) ng = 0 ok = 1 << 20 while ok - ng > 1: m = (ok + ng) // 2 if m * m < A + B: ng = m else: if A * B < ((m * m - (A + B)) // 2) ** 2: ok = m else: ng = m print(ok) return 0 main()