#include using namespace std; using int64 = long long; const int mod = 1e9 + 7; int dp[200001][2][3]; int dp2[6][2][3][800]; string S; int P; int rec2(int idx, bool f, int latte, bool lim, int beet) { if(f)latte = 0; if(idx == -1) return (f || latte == 0) && beet != 0; if(!lim && ~dp2[idx][f][latte][beet]) return dp2[idx][f][latte][beet]; int ret = 0; for(int i = (lim ? S[idx] - '0' : 9); i >= 0; i--) { ret += rec2(idx - 1, f | (i == 3), (latte * 10 + i) % 3, lim & (i == S[idx] - '0'), (beet * 10 + i) % P); if(ret >= mod) ret -= mod; } if(!lim) return dp2[idx][f][latte][beet] = ret; return ret; } int rec(int idx, bool f, int latte, bool lim) { if(f)latte = 0; if(idx <= 5) return rec2(idx, f, latte, lim, 0); if(!lim && ~dp[idx][f][latte]) return dp[idx][f][latte]; int ret = 0; for(int i = (lim ? S[idx] - '0' : 9); i >= 0; i--) { ret += rec(idx - 1, f | (i == 3), (latte * 10 + i) % 3, lim & (i == S[idx] - '0')); if(ret >= mod) ret -= mod; } if(!lim) return dp[idx][f][latte] = ret; return ret; } int beet(const string &x) { S = x; return rec((int) S.size() - 1, false, 0, true); } int main() { string A, B; cin >> A >> B >> P; reverse(begin(A), end(A)); for(int i = 0; i < A.size(); i++) { if(A[i] == '0') { A[i] = '9'; } else { A[i]--; break; } } reverse(begin(B), end(B)); memset(dp, -1, sizeof(dp)); memset(dp2, -1, sizeof(dp2)); cout << (beet(B) + mod - beet(A)) % mod << endl; }