## https://yukicoder.me/problems/no/2624 def solve(N, S): s_array = S.split(".") s = int(s_array[0]) * 1000 + int(s_array[1]) ans = 0 if N >= 1001: ans = N - 1000 for n in range(1, min(N, 1000) + 1): s1 = s * n s2 = s * n + n s1 %= 1000 s2 %= 1000 if s1 == 0: ans += 1 elif s2 < s1 and s2 > 0: ans += 1 return ans def main(): T = int(input()) answers = [] for _ in range(T): N, S = input().split() ans = solve(int(N), S) answers.append(ans) for ans in answers: print(ans) if __name__ == "__main__": main()