import java.util.Scanner; public class Main { private static final int MOD = 1_000_000_007; public static void main(String[] args) { try (Scanner in = new Scanner(System.in)) { String A = in.next(); String B = in.next(); int sekaiA = sekai(A.toCharArray(), true); int sekaiB = sekai(B.toCharArray(), false); System.out.println(sekaiB - sekaiA); } } private static int sekai(char[] N, boolean ignoreAllTight) { final int n = N.length; // position, tight, mod3, has3, mod8 final int[][][][][] dp = new int[n + 1][2][3][2][8]; dp[0][1][0][0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 2; l++) { for (int m = 0; m < 8; m++) { int lim = j == 1 ? N[i] - '0' : 9; for (int d = 0; d < lim + 1; d++) { int nj = j == 1 && d == lim ? 1 : 0; int nk = (10 * k + d) % 3; int nl = l == 1 || d == 3 ? 1 : 0; int nm = (10 * m + d) % 8; dp[i + 1][nj][nk][nl][nm] += dp[i][j][k][l][m]; dp[i + 1][nj][nk][nl][nm] %= MOD; } } } } } } int sum = 0; for (int j = 0; j < (ignoreAllTight ? 1 : 2); j++) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 2; l++) { for (int m = 0; m < 8; m++) { if ((k == 0 || l == 1) && m != 0) { sum += dp[n][j][k][l][m]; sum %= MOD; } } } } } return sum; } }