def solve(): N, S = input().split() N = int(N); S = int(S.replace(".", "")) cnt = 0 for i in range(1, min(N, 999) + 1): left = S*i; right = left + i if left < right // 1000 * 1000 < right: cnt += 1 cnt += max(N - 999, 0) print(cnt) T = int(input()) for _ in range(T): solve()