#include #define range(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,b) for(int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; //const int INF = 1e8; const long long M = 1000000007; using namespace std; long long dp[10005][2][2][3][8] = {0}; //i文字まで見た、sより小さい、3が含まれる、mod 3, mod8 long long solve(string s, bool f){ memset(dp, 0, sizeof(dp)); dp[0][0][0][0][0] = 1; rep(i,s.size()) rep(j,2) rep(k,2) rep(l,3) rep(m,8) { int lim = j ? 9 : s[i] - '0'; rep(d,lim + 1){ (dp[i + 1][j || d < lim][k || (d == 3)][(l + d) % 3][(m * 10 + d) % 8] += dp[i][j][k][l][m]) %= M; } } long long ans = 0, less = 0; rep(j,2) rep(k,3) rep(l,8) if((j || k == 0) && l != 0){ ans += dp[s.size()][1][j][k][l]; less += dp[s.size()][0][j][k][l]; } return (ans - (f ? 0 : less)) % M; } int main(){ string a, b; cin >> a >> b; cout << (solve(b,0) - solve(a,1) + M) % M << endl; }