// #pragma GCC optimize("O3,unroll-loops") #include // #include using namespace std; #if __cplusplus >= 202002L using namespace numbers; #endif int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); auto __solve_tc = [&](auto __tc_num)->int{ long long th; string s; cin >> th >> s; erase(s, '.'); int avg = stoi(s) % 1000; long long res = 0; { // 0 int req = 1000 / gcd(avg, 1000); res += th / req; } if(gcd(avg, 1000) == 1){ // 999 int inv = 1; { int base = avg; for(auto e = 399; e; e >>= 1){ if(e & 1){ inv = inv * base % 1000; } base = base * base % 1000; } } int rem = 999 * inv % 1000; if(th >= rem){ res += 1 + (th - rem) / 1000; } } cout << res << "\n"; return 0; }; int __tc_cnt; cin >> __tc_cnt; for(auto __tc_num = 0; __tc_num < __tc_cnt; ++ __tc_num){ __solve_tc(__tc_num); } return 0; } /* */