n = int(input()) for i in range(n): a,b = map(int,input().split()) l = 4 * a * b for x in range(10**7): r = x**2 - a - b if r < 0: continue else: r **= 2 if l < r: print(x) break