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