from itertools import product A,B = map(int,input().split()) A = str(A-1) B = str(B) mod=10**9+7 def count(a): n = len(a) dp=[[[[[0] * 8 for i in range(2)] for j in range(3)] for k in range(2)] for l in range(n+1)] dp[0][0][0][0][0] = 1 for i, less, mod3, has3, mod8 in product(range(n), (0,1), range(3), (0,1), range(8)): max_d = 9 if less else int(a[i]) for d in range(max_d+1): less_ = less or d < max_d mod3_ = (mod3*10+d)%3 has3_ = has3 or d==3 mod8_ = (mod8*10+d)%8 dp[i + 1][less_][mod3_][has3_][mod8_] = (dp[i + 1][less_][mod3_][has3_][mod8_]+dp[i][less][mod3][has3][mod8])%mod cnt = 0 for less,mod8 in product((0,1),range(1,8)): cnt = (cnt+dp[n][less][0][1][mod8])%mod cnt = (cnt+dp[n][less][1][1][mod8])%mod cnt = (cnt+dp[n][less][2][1][mod8])%mod cnt = (cnt+dp[n][less][0][0][mod8])%mod return cnt print((count(B)-count(A))%mod)