import sys input = sys.stdin.readline T=int(input()) for tests in range(T): X,Y=map(int,input().split()) if X==Y: xr=round(X**(1/2)) LIST=[] for i in range(1,xr+1): if X%i==0: LIST.append(i) if X//i>i: LIST.append(X//i) ANS=X-1 for l in LIST: A=l-1 if A==1: continue else: B=X//(A+1) if A>0 and B>0: ANS+=1 print(ANS) continue if Xi: LIST.append((X-Y)//i) ANS=0 for l in LIST: A=l+1 if A>0 and (X+Y)%(A+1)==0: k=(X-Y)//(A-1) l=(X+Y)//(A+1) if (k+l)%2==0 and k+l>0 and (l-k)%2==0 and l-k>0: ANS+=1 print(ANS)