T=int(input()) for i in range(T): x,y=input().split() if y=='100.000': print(x) else: y=y.replace('.','') x,y=int(x),int(y) ans=0 for i in range(1,min(1001,x+1)): if y*i%1000==0: ans+=1 else: c=100*i cc=10**5 p,q=y*c//cc,(y+1)*c//cc if p!=q: pp,qq=y*c//cc,(y+1)*c//cc c=int((pp+1)/i*1000) if y==c: ans+=1 if x>1000: ans+=x-1000 print(ans)