#include <bits/stdc++.h>
char A[502], B[502];
int M;
int dp[501][2][10][3][501];
int rec(const std::string &br, int i, bool smaller, int prv, short up,
        int mod) {
  if (i == br.size()) return !mod;
  int &ret = dp[i][smaller][prv][up][mod];
  if (~ret) return ret;
  ret = 0;
  for (int d = 0; d < (smaller ? 10 : br[i] - '0' + 1); ++d)
    if (!d || d != prv)
      if (up == 2 || up == 1 && d < prv || !up && d > prv)
        ret = (ret + rec(br, i + 1, smaller | d != br[i] - '0', d,
                         up == 2 && !prv ? 2 : d > prv, (mod * 10 + d) % M)) %
              10000;
  return ret;
}
int main() {
  scanf("%s%s%d", A, B, &M);
  int c = 1, e = strlen(A) - 1;
  for (int i = (e); i >= 0; --i) {
    A[i] -= c;
    c = 0;
    if (A[i] - '0' < 0) A[i] += 10, c = 1;
  }
  printf("%s %s\n", A, B);
  memset((dp), (-1), sizeof(dp));
  int upr = rec(B, 0, false, 0, 2, 0);
  memset((dp), (-1), sizeof(dp));
  int lwr = rec(A, 0, false, 0, 2, 0);
  printf("%d\n", (upr - lwr + 10000) % 10000);
  return 0;
}
