#include <bits/stdc++.h>
using namespace std;
const int mod = 10000;
int dp[600][600][11][2][2];
string S, T;
int power[600], n;
int solve(string V) {
  for (int i = 0; i < 360000; i++) {
    for (int j = 0; j < 10; j++) {
      dp[i / 600][i % 600][j][0][0] = 0;
      dp[i / 600][i % 600][j][0][1] = 0;
      dp[i / 600][i % 600][j][0][0] = 0;
      dp[i / 600][i % 600][j][0][1] = 0;
    }
  }
  dp[0][0][0][0][1] = 1;
  dp[0][0][10][1][1] = 1;
  for (int i = 0; i < (int)V.size(); i++) {
    int P = V[i] - '0';
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < 11; k++) {
        for (int l = 0; l < 2; l++) {
          int L = 0, R = 9;
          if (l == 0) L = k + 1;
          if (l == 1) R = k - 1;
          for (int m = L; m <= R; m++) {
            int Plus = (power[i] * m) % n;
            int to = (j + Plus) % n;
            dp[i + 1][to][m][1 - l][0] += dp[i][j][k][l][0];
            if (P > m) dp[i + 1][to][m][1 - l][0] += dp[i][j][k][l][1];
            if (P == m) dp[i + 1][to][m][1 - l][1] += dp[i][j][k][l][1];
          }
        }
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 2; j++) {
      sum += dp[V.size()][0][i][j][0] + dp[V.size()][0][i][j][1];
    }
  }
  cout << sum << endl;
  return sum;
}
int main() {
  cin >> S >> T >> n;
  int v = 1;
  for (int i = S.size() - 1; i >= 0; i--) {
    power[i] = v;
    v *= 10;
    v %= n;
  }
  cout << (solve(T) - solve(S) + mod) % mod << endl;
  return 0;
}
