#include <bits/stdc++.h>
template <typename T>
using duo = std::pair<T, T>;
template <typename T>
using vec = std::vector<T>;
using ll = long long;
template <typename T, typename U>
inline bool chmax(T& x, U a) {
  return x < a && (x = a, 1);
}
template <typename T, typename U>
inline bool chmin(T& x, U a) {
  return a < x && (x = a, 1);
}
template <typename T = int>
inline T in() {
  T x;
  std::cin >> x;
  return x;
}
template <typename T = int>
inline vec<T> in(int n) {
  vec<T> v;
  v.reserve(n);
  for (int i = (0); i < (int)(n); ++i) v.emplace_back(in<T>());
  return v;
}
template <typename T>
vec<T> ndvec(T v, int n) {
  return vec<T>(n, v);
}
template <typename T, typename... Ts>
auto ndvec(T v, int n, Ts... ns) -> vec<decltype(ndvec(v, ns...))> {
  return ndvec(ndvec(v, ns...), n);
}
template <typename T>
inline void pr(T x) {
  std::cout << x << '\n';
}
template <typename T, typename... Ts>
inline void pr(T x, Ts... xs) {
  std::cout << x << ' ';
  pr(xs...);
}
inline int re() {
  int x = 0, m = 0, k;
  for (;;) {
    (k) = getchar_unlocked();
    if (k == '-') {
      m = 1;
      break;
    }
    if ('0' <= k && k <= '9') {
      x = k - '0';
      break;
    }
  }
  for (;;) {
    (k) = getchar_unlocked();
    if (k < '0' || '9' < k) break;
    x = x * 10 + k - '0';
  }
  return x;
}
inline void wr(int x, char c = '\n') {
  int s = 0, m = 0;
  char b[32];
  if (x < 0) m = 1, x = -x;
  for (; x; x /= 10) b[s++] = x % 10;
  if (!s) b[s++] = 0;
  if (m) putchar_unlocked('-');
  for (; s--;) putchar_unlocked(b[s] + '0');
  putchar_unlocked(c);
}
struct IoSetup {
  IoSetup() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(10);
    std::cerr.precision(10);
  }
} iosetup;
using namespace std;
const int inf = 1001001001;
const ll infll = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};
const int MOD = ((ll)(1e4));
int memo[501][10][2][2][500];
struct ZigZagNumber {
  const string S;
  const int N;
  const int M;
  ZigZagNumber(const string& S, int M) : S(S), N(S.size()), M(M) {}
  int dfs(int i, int pre, bool high, bool tight, int tot) {
    if (i == N) {
      return tot == 0;
    }
    int& ret = memo[i][pre][high][tight][tot];
    if (ret != -1) return ret;
    int x = S[i] - '0';
    int l = 0, r = 10;
    if (high) {
      l = pre + 1;
    } else {
      r = pre;
    }
    if (tight) chmin(r, x + 1);
    ret = 0;
    for (int j = (l); j < (int)(r); ++j) {
      ret += dfs(i + 1, j, !high, tight && j == x, (10 * tot + j) % M);
    }
    return ret %= MOD;
  }
  int solve() {
    memset(memo, -1, sizeof(memo));
    int ret = 0;
    for (int k = (0); k < (int)(N); ++k) {
      int x = S[k] - '0';
      int l = 1, r = 10;
      if (k == 0) chmin(r, x + 1);
      for (int i = (l); i < (int)(r); ++i) {
        bool tight = k == 0 && i == x;
        ret += dfs(k + 1, i, true, tight, i % M);
        if (k < N - 1) {
          ret += dfs(k + 1, i, false, tight, i % M);
        }
      }
      ret %= MOD;
    }
    return ret;
  }
};
string decr(string s) {
  for (int i = (s.size()) - 1; i >= (int)(0); --i) {
    if (s[i]-- != '0') break;
    s[i] = '9';
  }
  return s.substr(s.size() > 1 && s[0] == '0');
}
signed main() {
  auto A = decr(in<string>());
  auto B = in<string>();
  int M = in();
  pr(ZigZagNumber(B, M).solve() - ZigZagNumber(A, M).solve());
  return 0;
}
