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) left = 0 while S[left] != ".": left += 1 S = int(S[left+1:]) print(N//D[S])