#include #include using namespace std; using namespace atcoder; using mint = modint998244353; using ll = long long; #define all(x) x.begin(), x.end() #define rep(i, n) for (int i = 0; i < n; i++) ll f(ll r, ll k, ll c){ ll n = r / k; ll ans = 0; ll d = 1; for(int i = 0; i < 9; i++){ ll x = c * d; ll y = (c + 1) * d; d *= 10; ans += floor_sum(n, d, k, d + k - x) - floor_sum(n, d, k, d + k - y); } return ans; } ll solve(){ ll l, r, k, c; cin >> l >> r >> k >> c; return f(r, k, c) - f(l - 1, k, c); } int main(void) { int t; cin >> t; rep(i, t){ cout << solve() << endl; } return 0; }