#!/usr/bin/ python3.8 import sys sys.set_int_max_str_digits(10**5) read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines A, B = map(int, read().split()) MOD = 10**9 + 7 def f(N): """0以上N以下で数える""" N = tuple(map(int, '000' + str(N))) dp0 = [1, 0, 0] # 3のついていない数、N以下 dp1 = [0, 0, 0] # 3のついていない数、N-1以下 full = 0 for n in N[:-3]: full *= 10 full += n full %= MOD newdp0 = [0, 0, 0] newdp1 = [0, 0, 0] for i in range(10): if i == 3: continue if n >= i: for d in range(3): newdp0[(i + d) % 3] += dp0[d] else: for d in range(3): newdp0[(i + d) % 3] += dp1[d] if n >= i + 1: for d in range(3): newdp1[(i + d) % 3] += dp0[d] else: for d in range(3): newdp1[(i + d) % 3] += dp1[d] dp0 = [x % MOD for x in newdp0] dp1 = [x % MOD for x in newdp1] n = int(''.join(map(str, N[-3:]))) full8 = full * 125 full8 += n // 8 + 1 full *= 1000 full += n + 1 no_aho_no8 = 0 for i in range(1000): if i % 8 == 0: continue if str(i).count('3'): continue if i <= n: for j in range(3): if (i + j) % 3 != 0: x = dp0[j] no_aho_no8 += x if i > n: for j in range(3): if (i + j) % 3 != 0: x = dp1[j] no_aho_no8 += x return (full - full8 - no_aho_no8) % MOD def f_naive(N): N = int(''.join(map(str, N))) ret = 0 for i in range(N + 1): if i % 3 == 0 or str(i).count('3'): if i % 8 != 0: ret += 1 return ret answer = f(B) - f(A - 1) answer %= MOD print(answer)