n=int(input()) for j in range(n): a,b=map(int,input().split()) co=0 for i in reversed(range(30)): co+=2**i if co**2>4*a*b: co-=2**i cco=0 for i in reversed(range(30)): cco+=2**i if cco**2>a+b+co: cco-=2**i print(cco+1)