import sys sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = -1-(-1 << 31) inf = -1-(-1 << 62) md = 10**9+7 # md = 998244353 def digitdp(aa,eq,p): res=0 dp = [[[0]*800 for _ in range(3)] for _ in range(2)] jf = jm3 = jm8 = 0 for i, a in enumerate(aa): ndp = [[[0]*800 for _ in range(3)] for _ in range(2)] # 未満確定からの遷移 for f in range(2): for m3 in range(3): for m8 in range(800): if i=len(aa)-6 else 0 ndp[nf][nm3][nm8]+=pre # ちょうどからの遷移 for d in range(i == 0, a): nf = jf | (d == 3) nm3 = (jm3*10+d)%3 nm8 = (jm8*10+d)%800 if i >= len(aa)-6 else 0 ndp[nf][nm3][nm8] += 1 # その桁からのスタート if i: for d in range(1, 10): ndp[d==3][d%3][d if i >= len(aa)-6 else 0] += 1 # ちょうどの更新 jf|=a==3 jm3=(jm3*10+a)%3 jm8=(jm8*10+a)%800 dp = ndp if eq and (jf or jm3%3 == 0) and jm8%p:res+=1 for f in range(2): for m3 in range(3): for m8 in range(800): if (f or m3%3==0) and m8%p: res+=dp[f][m3][m8] res%=md return res a,b,p=SI().split() aa=list(map(int,a)) bb=list(map(int,b)) p=int(p) ans=digitdp(bb,1,p)-digitdp(aa,0,p) print(ans%md)