def main(): N = int(input()) for _ in range(N): A, B = map(int, input().split()) max_x = int(1e9) min_x = 2 while max_x - min_x > 1: mid_x = (max_x + min_x) // 2 if 4 * A * B < (mid_x**2 - A - B)**2: max_x = mid_x else: min_x = mid_x print(max_x) # A+B+2√AB < X^2 # 2√AB < X^2-A-B # 4AB < (X^2-A-B)^2 if __name__ == "__main__": main()