#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=10000;
int dp[2][777][10][2][2][10000]={0};
char A[2][505];
int M;

char tmp[506];

int dfs(int x,int d,int n,bool f,int up,int mod)
{
	//printf("%d %d %d %d %d %d\n",x,d,n,f,up,mod);
	//if(dp[x][d][n][f][up][mod]>0)return dp[x][d][n][f][up][mod];
	if(d==strlen(A[x]))
	{
	//	if(mod==0)puts(tmp);
		return mod==0;
	}
	int res=0;
	int ub=(f?9:A[x][d]-'0');
	for(int i=0;i<=ub;i++)
	{
		if(up==0&&n<=i)continue;
		if(up==1&&n>=i)continue;
		if(up==2&&n&&n==i)continue;

		int nf;
		if(up==2)
		{
			if(n==0)nf=2;
			else if(n>i)nf=1;
			else nf=0;
		}else nf=!up;
		tmp[d]=i+'0';
		res=(res+dfs(x,d+1,i,f|(i!=A[x][d]-'0'),nf,(mod*10+i)%M));
	}
	return dp[x][d][n][f][up][mod]=res;
}


int main()
{
	//memset(dp,-1,sizeof(dp));
	scanf("%s%s%d",A[0],A[1],&M);
	for(int i=0;A[0][i];i++)A[0][i]=A[0][i]=='0'?'9':A[0][i]-1;
	printf("%d\n",(dfs(1,0,0,0,2,0)-dfs(0,0,0,0,2,0))%MOD);
	return 0;
}