#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(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); //i=0では必ず条件を満たす(sum=S) ans += N/1000; for (int i=1; i<1000; i++){ x = (S*i+999) / 1000 * 1000; if (x < (S+1)*i && i <= N){ //N以下の整数のうち、1000で割ってi余るものの個数 ans += (N-i)/1000+1; } } cout << ans << endl; } return 0; }