#めぐる式二分探索 #参考サイト:https://aotamasaki.hatenablog.com/entry/meguru_bisect def is_ok(m): return (m*1000)//i>=s def meguru_bisect(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok T = int(input()) for _ in range(T): n,s = input().split() n = int(n) s = s.split('.') s = int(s[0]+s[1]) ans = max(0,n-1000) for i in range(1,min(1000,n)+1): v = meguru_bisect(0,i*100) if (v*1000)//i==s: ans+=1 print(ans)