import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 A, B, P = readline().split() P = int(P) A = [0, 0, 0, 0, 0] + [int(x) - ord('0') for x in A] B = [0, 0, 0, 0, 0] + [int(x) - ord('0') for x in B] def solve(A, P, include=True): total = 0 no_3 = 0 cnt = (0, 1, 2, 3, 3, 4, 5, 6, 7, 8) full_use_3 = False MOD3 = 3 * MOD for x in A[:-6]: total = (10 * total + x) % MOD3 no_3 = (9 * no_3) % MOD if not full_use_3: no_3 += cnt[x] full_use_3 |= x == 3 n = no_3 * 3 no_3 = [n, n, n] x = A[-6] full_use_3 |= 3 in A[:-6] for d in range(x): if full_use_3 or d == 3: continue no_3[(total + d) % 3] += 1 total = (total * 10 + x) % MOD3 use_3 = (total - sum(no_3)) % MOD full_mod_3 = total % 3 U = 0 for x in A[-5:]: U = 10 * U + x ret = 0 for x in range(10**5): if x % P == 0: continue if '3' in str(x): ret += total else: ret += use_3 + no_3[(-x) % 3] for x in range(U + include): if x % P == 0: continue if '3' in str(x) or full_use_3: ret += 1 else: ret += (full_mod_3 + x) % 3 == 0 return ret def solve_naive(A, P, include): N = 0 for x in A: N = 10 * N + x ret = 0 for x in range(N + include): if x % P == 0: continue ret += '3' in str(x) or x % 3 == 0 return ret x = solve(B, P, True) - solve(A, P, False) print(x % MOD)