// #include #include using namespace std; using namespace atcoder; using ll = long long; #define rep(i, n) for (int i=0; i<(int)(n); ++(i)) #define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i)) #define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i)) #define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i)) #define all(x) (x).begin(), (x).end() const int INF = (int)(1e9); int main() { int t0; cin >> t0; rep(i0, t0) { ll n; string s; cin >> n >> s; int pi = s.find('.'), si = stoi(s.substr(0, pi)) * 1000 + stoi(s.substr(pi+1)); ll li = 0, ri = n+1; while (ri-li > 1) { ll ci = li + (ri-li) / 2, lval = si * ci, rval = (si+1) * ci; if (lval/1000 == rval/1000) li = ci; else ri = ci; } ll res = (n+1) - ri; rep3(i, 1, ri) if (si*(ll)i%1000 == 0) ++res; cout << res << endl; } return 0; }