#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
const int kaijou[10] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
const int M = 10000;
int dp[502][2][10][502];
int modpow(int x, int k, int m) {
  if (k == 0) return 1;
  int tmp = modpow(x, k / 2, m);
  tmp *= tmp;
  tmp %= m;
  if (k & 1) {
    tmp *= x;
    tmp %= m;
  }
  return tmp;
}
int solver(string s, int m) {
  int n = s.size();
  if (n == 0) return 0;
  if (n == 1) {
    return (s[0] - '0') / m;
  }
  int ret = 0;
  for (int i = 1; i <= s[0] - '0' - 1; i++) {
    ret += dp[n][0][i][0];
    ret += dp[n][1][i][0];
    ret %= M;
  }
  for (int i = 2; i <= n - 1; i++) {
    for (int j = 1; j <= 9; j++) {
      ret += dp[i][0][j][0];
      ret += dp[i][1][j][0];
      ret %= M;
    }
  }
  ret += 9 / m;
  ret %= M;
  int a = -1, b = s[0] - '0';
  int sum = 10 * m - b * modpow(10, n - 1, m);
  sum %= m;
  for (int i = 1; i <= n - 1; i++) {
    int c = s[i] - '0';
    if (a == -1) {
      if (c <= b) {
        for (int j = 0; j < c; j++) {
          ret += dp[n - i][0][j][sum];
          ret %= M;
        }
        if (c == b) break;
        a = b;
        b = c;
        sum += 10 * m - b * modpow(10, n - i - 1, m);
        sum %= m;
      } else {
        for (int j = 0; j < b; j++) {
          ret += dp[n - i][0][j][sum];
          ret %= M;
        }
        for (int j = b + 1; j < c; j++) {
          ret += dp[n - i][1][j][sum];
          ret %= M;
        }
        a = b;
        b = c;
        sum += 10 * m - b * modpow(10, n - i - 1, m);
        sum %= m;
      }
    } else {
      if (a < b) {
        if (c < b) {
          for (int j = 0; j < c; j++) {
            ret += dp[n - i][0][j][sum];
            ret %= M;
          }
          a = b;
          b = c;
          sum += 10 * m - b * modpow(10, n - i - 1, m);
          sum %= m;
        } else {
          for (int j = 0; j < b; j++) {
            ret += dp[n - i][0][j][sum];
            ret %= M;
          }
          break;
        }
      } else {
        if (c <= b)
          break;
        else {
          for (int j = b + 1; j < c; j++) {
            ret += dp[n - i][1][j][sum];
            ret %= M;
          }
          a = b;
          b = c;
          sum += 10 * m - b * modpow(10, n - i - 1, m);
          sum %= m;
        }
      }
    }
    if (i == n - 1 && sum == 0) ret++;
  }
  return ret;
}
int main() {
  string a, b;
  int m;
  cin >> a >> b >> m;
  for (int i = a.size() - 1; i >= 0; i--) {
    if (a[i] != '0') {
      a[i]--;
      break;
    }
    a[i] = '9';
  }
  if (a[0] == '0') {
    string a_ = "";
    for (int i = 1; i <= a.size() - 1; i++) a_ += a[i];
    a = a_;
  }
  for (int i = 0; i < 10; i++) {
    dp[1][0][i][i % m] = 1;
    dp[1][1][i][i % m] = 1;
  }
  for (int i = 2; i < 502; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < m; k++) {
        int c = (k + 10 * m - j * modpow(10, i - 1, m)) % m;
        dp[i][0][j][k] = 0;
        for (int l = j + 1; l < 10; l++) {
          dp[i][0][j][k] += dp[i - 1][1][l][c];
        }
        dp[i][1][j][k] = 0;
        for (int l = 0; l < j; l++) {
          dp[i][1][j][k] += dp[i - 1][0][l][c];
        }
      }
    }
  }
  printf("%d\n", (solver(b, m) - solver(a, m) + m) % m);
}
