import bisect import copy import decimal import fractions import heapq import itertools import math import random import sys import time from collections import Counter,deque,defaultdict from functools import lru_cache,reduce from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max def _heappush_max(heap,item): heap.append(item) heapq._siftdown_max(heap, 0, len(heap)-1) def _heappushpop_max(heap, item): if heap and item < heap[0]: item, heap[0] = heap[0], item heapq._siftup_max(heap, 0) return item from math import gcd as GCD read=sys.stdin.read readline=sys.stdin.readline readlines=sys.stdin.readlines write=sys.stdout.write A,B=readline().split() A=list(map(int,list(A))) B=list(map(int,list(B))) mod=10**9+7 def solve(N): if len(N)<=5: ans=0 N=int("".join(map(str,N))) for n in range(1,N): if (n%3==0 or "3" in str(n)) and n%8: ans+=1 return ans dp0=[0]*3 dp1=[0]*3 for i in range(1,N[0]): if i==3: dp1[i%3]+=1 else: dp0[i%3]+=1 s=N[0] bl=(N[0]==3) for n in N[1:-3]: prev0=dp0 prev1=dp1 dp0=[0]*3 dp1=[0]*3 for p in range(3): for i in range(10): if i==3: dp1[(p*10+i)%3]+=prev0[p] dp1[(p*10+i)%3]+=prev1[p] else: dp0[(p*10+i)%3]+=prev0[p] dp1[(p*10+i)%3]+=prev1[p] for i in range(n): if bl|(i==3): dp1[(s*10+i)%3]+=1 else: dp0[(s*10+i)%3]+=1 for i in range(1,10): if i==3: dp1[i%3]+=1 else: dp0[i%3]+=1 s=s*10+n bl|=n==3 X=N[-3]*100+N[-2]*10+N[-1] ans=0 for i in range(3): for x in range(1000): if x%8==0: continue if (i+x)%3==0 or "3" in str(x): ans+=dp0[i] ans+=dp1[i] for x in range(1,1000): if x%8==0: continue if x%3==0 or "3" in str(x): ans+=1 for x in range(1,X): if x%8==0: continue if (s+x)%3==0 or "3" in str(x) or bl: ans+=1 return ans%mod ans=(solve(B)-solve(A))%mod B+=[0]*2 if 3 in B and sum(B)%3==0 and (B[2]*100+B[1]*10+B[0])%8==0: ans+=1 ans%=mod print(ans)