#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
template <class T>
T RoundOff(T a) {
  return int(a + .5 - (a < 0));
}
template <class T, class C>
void chmax(T& a, C b) {
  if (a < b) a = b;
}
template <class T, class C>
void chmin(T& a, C b) {
  if (b < a) a = b;
}
template <class T, class C>
pair<T, C> mp(T a, C b) {
  return make_pair(a, b);
}
const int MOD = 10000;
int memo[502][10][2][2][502][2];
string A, B;
int M;
int calc_rest(int x, int n, int v) {
  for (int i = 0; i < n; i++) {
    x -= (x / v) * v;
    x *= 10;
  }
  return x / 10;
}
string dec(string S) {
  for (int i = S.size() - 1; 0 <= i; i--) {
    if (S[i] != '0') {
      S[i]--;
      if (S[i] == '0' && i == 0 && 1 < S.size()) S = S.substr(1);
      return S;
    } else
      S[i] = '9';
  }
  return S;
}
int rec(string& S, int pnt, int prv, bool inc, bool sp, int rest, bool zero) {
  if (pnt == S.size()) return rest == 0;
  if (memo[pnt][prv][inc][sp][rest][zero] != -1)
    return memo[pnt][prv][inc][sp][rest][zero];
  int dig = S.size() - pnt;
  long long res = 0;
  if (inc) {
    int lim = (sp ? 10 : S[pnt] - '0' + 1);
    for (int i = prv + 1; i < lim; i++) {
      res += rec(S, pnt + 1, i, false, sp || i < S[pnt] - '0',
                 (rest + calc_rest(i, dig, M)) % M, false);
      res %= MOD;
    }
  } else {
    for (int i = prv - 1; zero <= i; i--) {
      res += rec(S, pnt + 1, i, true, sp || i < S[pnt] - '0',
                 (rest + calc_rest(i, dig, M)) % M, false);
      res %= MOD;
    }
  }
  return memo[pnt][prv][inc][sp][rest][zero] = res;
}
int count(string& S) {
  if (S.size() == 1) return (S[0] - '0') / M;
  memset(memo, -1, sizeof memo);
  long long res = 9 / M;
  for (int i = 1; i < S.size(); i++) {
    int inc = rec(S, S.size() - i - 1, 0, true, i != S.size() - 1, 0, true);
    int fal =
        rec(S, S.size() - i - 1, (i == S.size() - 1 ? S[0] - '0' + 1 : 10),
            false, i != S.size() - 1, 0, true);
    res += inc + fal;
    res %= MOD;
  }
  return res;
}
int solve() {
  A = dec(A);
  return (count(B) - count(A) + MOD) % MOD;
}
int main() {
  cin >> A >> B >> M;
  cout << solve() << endl;
}
