def divisor_list(x): res=[] i=1 while i*i<=x: if x%i==0: res.append(i) if i*i!=x: res.append(x//i) i+=1 return res n=int(input()) for i in range(n): ans=0 x,y=map(int,input().split()) #print(x,y) Dy=divisor_list(y) for d in Dy: if d%2==0: continue b=(d+1)/2 if 2*b*(b-1)*y%((2*b-1)*x)!=0: continue A=2*b*(b-1)*y//((2*b-1)*x) if A<=0 or A>100000000: continue if A<=2*b-1: continue ans+=1 for d in Dy: if d%2==0: continue a=(d+1)/2 if 2*a*(a-1)*y%((2*a-1)*(y-x))!=0: continue B=2*a*(a-1)*y//((2*a-1)*(y-x)) if B<=0 or B>100000000: continue if B<=2*a-1: continue ans+=1 if y>2*x: ans+=100000000//y if y>2*(y-x): ans+=100000000//y print(ans)