# 公式解説より、1000を超えれば常に可能なので1000までを調べる from math import ceil, floor T = int(input()) for t in range(T): N, S = map(float, input().split()) N = int(N) S1000 = int(S*1000) ans = 0 for n in range(1, min(1000, N)+1): low = (S1000*n-1)//1000 high = ((S1000+1)*n-1)//1000 if low != high: ans += 1 #print('n', n, 'low', low, 'high', high) ans += max(0, N-1000) print(ans)