#include #define rep(i, a) for (int i = 0; i < (a); i++) #define rep2(i, a, b) for (int i = (a); i < (b); i++) #define repr(i, a) for (int i = (a) - 1; i >= 0; i--) #define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--) using namespace std; typedef long long ll; const ll inf = 1e9; const ll mod = 1e9 + 7; ll dp[10002][2][2][3][8]; // ind, below, use3, mod3, mod8 ll solve(string N) { memset(dp, 0, sizeof(dp)); dp[0][0][0][0][0] = 1; rep (i, N.length()) { rep (j, 2) rep (k, 2) rep (l, 3) rep (m, 8) { int ub = j == 0 ? N[i] - '0' : 9; rep (n, ub + 1) { (dp[i + 1][j || n != ub][k || n == 3][(l + n) % 3][(n + m * 10) % 8] += dp[i][j][k][l][m]) %= mod; } } } ll ans = 0; rep (j, 2) rep (k, 2) rep (l, 3) rep2 (m, 1, 8) { if (k || l == 0) { (ans += dp[N.length()][j][k][l][m]) %= mod; } } return ans; } ll modulo(ll a) { a %= mod; a += mod; a %= mod; return a; } string decrement(string S) { int bollow = 1; repr (i, S.length()) { int p = S[i] - '0'; if (p - bollow < 0) { S[i] = '9'; bollow = 1; } else { S[i] = (p - bollow) + '0'; break; } } return S; } int main() { string A, B; cin >> A >> B; ll b = solve(B); ll a = solve(decrement(A)); cout << modulo(b - a) << endl; }