#include using namespace std; using ll = long long; #define overload(_1, _2, _3, name, ...) name #define _for(i, a, b) for(int i = int(a); i= int(b); --i) #define _rrep(i, n) _rfor(i, n, 0) #define rrep(...) overload(__VA_ARGS__, _rfor, _rrep,)(__VA_ARGS__) template inline bool chmax(T&a, T b){ if(a < b){a = b; return 1;} return 0; } template inline bool chmin(T&a, T b){ if(a > b){a = b; return 1;} return 0; } const int mod = 1e9 + 7; string a, b; int dp[101010][2][2][3][8]; int main () { cin.tie(0) -> sync_with_stdio(false); cin >> a >> b; auto calc = [&](string s, int f) { memset(dp, 0, sizeof(dp)); dp[0][0][0][0][0] = 1; int n = s.size(); rep(i, n)rep(j, 2)rep(k, 2)rep(l, 3)rep(m, 8) { rep(d, (j ? 9 : s[i] - '0') + 1) { (dp[i + 1][j || d < s[i] - '0'][k || d == 3][(l + d) % 3][(m * 10 + d) % 8] += dp[i][j][k][l][m]) %= mod; } } int sum = 0; rep(k, 2)rep(l, 3)rep(m, 8) { if((k || l == 0) && m) { (sum += dp[n][1][k][l][m]) %= mod; if(f) (sum += dp[n][0][k][l][m]) %= mod; } } return sum; }; cout << (calc(b, 1) - calc(a, 0) + mod) % mod << '\n'; return 0; }