#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} int main(){ int t; cin >> t; vector> Q; rep(i, t){ long long n; long double x; cin >> n >> x; x -= int(x); x *= 1000; Q.emplace_back(n, int(round(x)), i); } sort(Q.begin(), Q.end()); int m = 0; vector v(1000); auto up = [&](){ m++; rep(i, m){ v[(1000 * i) / m]++; } }; vector ans(t); for(auto [n, y, idx] : Q){ while(m < n and m < 1000){ up(); } long long res = 0; res += v[y]; res += max(n - 1000, 0LL); ans[idx] = res; } rep(i, t){ cout << ans[i] << "\n"; } return 0; }