I=input N=int(I()) for i in range(N): A,B=map(int,I().split()) X=sqrt(A)+sqrt(B)-2 while 4*B*X*X>=(X*X-A+B)**2 or B>=X*X:X+=1 print(X)