T = int(input()) D = dict() for i in range(1, 1001): for j in range(1, i+1): n = j*1000//i%1000 if n not in D: D[n] = i for _ in range(T): N, S = input().split() N = int(N) if S.startswith("100"): S = int(S[4:]) else: S = int(S[3:]) print(N//D[S])