#include #include #include using namespace std; int main() { int T; cin >> T; while (T--) { long long N; cin >> N; string S; cin >> S; int len = S.size(); long long score = stoll(S.substr(0, len - 4)) * 1000 + stoll(S.substr(len - 3, 3)); long long ans = 0; for (long long i = 1; i <= min(N, 1000LL); i++){ if ((score * i - 1) / 1000 != ((score + 1) * i- 1) / 1000){ ans++; } } cout << ans + max(N - 1000LL, 0LL) << endl; } }