#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};
const int MOD = 10000;
int dp[501][500][10][3][2];
int M, L;
string N;
int solve(int n, int m, int last, int up, int same) {
  if (n == L) return !m;
  if (dp[n][m][last][up][same] != -1) return dp[n][m][last][up][same];
  int res = 0;
  for (int d = 0; d < (int)(10); d++) {
    int nsame = 0;
    if (same && d > N[n] - '0') break;
    if (same && d == N[n] - '0') nsame = 1;
    int nup = (up + 1) % 2;
    if (up == 0 && last >= d) continue;
    if (up == 1 && last <= d) continue;
    if (up == 2 && last && last == d) continue;
    if (up == 2) {
      if (last == 0)
        nup = 2;
      else if (last < d)
        nup = 1;
      else if (last > d)
        nup = 0;
      else
        assert(false);
    }
    res += solve(n + 1, (m * 10 + d) % M, d, nup, nsame);
    res %= MOD;
  }
  return dp[n][m][last][up][same] = res;
}
int main() {
  string A, B;
  cin >> A >> B >> M;
  for (int i = A.size() - 1; i >= 0; i--) {
    if (A[i] == '0')
      A[i] = '9';
    else {
      A[i]--;
      break;
    }
  }
  N = A;
  L = N.size();
  memset(dp, -1, sizeof(dp));
  int tmpa = solve(0, 0, 0, 2, 1);
  N = B;
  L = N.size();
  memset(dp, -1, sizeof(dp));
  int tmpb = solve(0, 0, 0, 2, 1);
  cout << (tmpb - tmpa + M) % M << endl;
}
