#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); //87.500 <= average < 87.501 //87500 <= 1000*average < 87501 //87500 <= 1000*s/k < 87501 //87500k/1000 <= s < 87501k/1000が整数解を持つk //k>=1000のとき、必ず存在する //87500k <= 1000s < 87501k ll T, N, S, ans, x; string U; cin >> T; while(T--){ cin >> N >> U; ans = 0; U.erase(remove(U.begin(), U.end(), '.'), U.end()); S = stoll(U); for (int i=1; i<1000; i++){ x = (S*i+999) / 1000 * 1000; if (x < (S+1)*i && i <= N) ans++; } ans += max(0LL, N-999); cout << ans << endl; } return 0; }