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,k): res=0 dp = [[0]*24 for _ in range(2)] jf = jm = 0 for i, a in enumerate(aa): ndp = [[0]*24 for _ in range(2)] # 未満確定からの遷移 for f in range(2): for m in range(24): pre = dp[f][m]%md if pre == 0: continue for d in range(10): nf=f|(d==3) nm=(m*10+d)%24 ndp[nf][nm]+=pre # ちょうどからの遷移 for d in range(i == 0, a): nf = jf | (d == 3) nm = (jm*10+d)%24 ndp[nf][nm] += 1 # その桁からのスタート if i: for d in range(1, 10): ndp[d==3][d] += 1 # ちょうどの更新 jf|=a==3 jm=(jm*10+a)%24 dp = ndp if i==len(aa)-k: if eq and (jf or jm%3==0) and jm%8==0:res-=1 for f in range(2): for m in range(24): if (f or m%3==0) and m%8==0: res-=dp[f][m] res%=md if eq and (jf or jm%3==0):res+=1 for f in range(2): for m in range(24): if f or m%3==0: res+=dp[f][m] res%=md return res a,b,p=SI().split() aa=list(map(int,a)) bb=list(map(int,b)) k=len(p) ans=digitdp(bb,1,k)-digitdp(aa,0,k) print(ans%md)