#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); vector> ok(100001); for(int i=1; i<=1000; i++){ int limit = i*100*1000; for(long long s=0; s<=limit; s+=1000){ long long now = s/i; ok.at(now).push_back(i); } } int T; cin >> T; while(T--){ long long N; cin >> N; string S; cin >> S; reverse(S.begin(),S.end()); long long T = 0,p10 = 1; for(auto c : S){ if(c == '.') continue; T += p10*(c-'0'); p10 *= 10; } long long answer = max(0LL,N-999); N = min(999LL,N); for(auto n : ok.at(T)){ if(n > N) break; answer++; } cout << answer << endl; } }