#include <cassert> #include <iostream> #include <string> using namespace std; int main() { int T; cin >> T; assert(T >= 1); assert(T <= 1000); while (T--) { long long N; cin >> N; assert(N >= 1); assert(N <= 10000000000000); string S; cin >> S; int len = S.size(); long long score = stoll(S.substr(0, len - 4)) * 1000 + stoll(S.substr(len - 3, 3)); assert(score >= 0 && score <= 100000); if (N <= 1000) { long long ans = 0; for (int i = 1; i <= N; i++) { long long lb = score * i; long long ub = (score + 1) * i - 1; if ((lb - 1) / 1000 != ub / 1000) { ans++; } } cout << ans << endl; } else { long long ans = N - 1000; for (int i = 1; i <= 1000; i++) { long long lb = score * i; long long ub = (score + 1) * i - 1; if ((lb - 1) / 1000 != ub / 1000) { ans++; } } cout << ans << endl; } } }