#include #include using namespace std; using namespace atcoder; typedef long long ll; ll solve(ll l,ll r,ll k,ll d,ll x){//count [l,r)*k mod d >=x ll c1 = floor_sum(r,d,k,0) - floor_sum(l,d,k,0); ll c2 = floor_sum(r,d,k,d - x) - floor_sum(l,d,k,d - x) - (r - l); return (r - l) - (c1 - c2); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while(t){ t--; ll l,r,k,c; cin >> l >> r >> k >> c; ll le = (l + k - 1)/k,ri = r/k + 1; ll i,ans = 0,now = 1; for(i=0;i<10;i++){ ans += solve(le,ri,k,now*10,now*c) - solve(le,ri,k,now*10,now*(c + 1)); now *= 10; } cout << ans << "\n"; } }