import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; immutable int MOD = 10^^9+7; int solve(string N, int P, bool less) { auto M = N.length; auto dp = new int[][][][][][][](M+1, 2, 3, 8, 2, 2, 2); // 桁, N未満か, mod3, 3がつくか, mod8, 最後から2番目の桁が0か, 最後の桁が0か dp[0][0][0][0][0][0][0] = 1; foreach (a; 0..M) { foreach (b; 0..2) { foreach (c; 0..3) { foreach (d; 0..8) { foreach (e; 0..2) { foreach (f; 0..2) { foreach (g; 0..2) { int digit = b ? 10 : N[a]-'0'+1; foreach (h; 0..digit) { int new_d; if (P == 800 && a >= M-2) new_d = d; else if (P == 80 && a == M-1) new_d = d; else new_d = (10*d+h) % 8; dp[a+1][b||(h0] += dp[a][b][c][d][e][f][g]; dp[a+1][b||(h0] %= MOD; } } } } } } } } int ret = 0; foreach (a; 0..2) { if (less && a == 0) continue; foreach (b; 0..3) { foreach (c; 0..8) { foreach (d; 0..2) { foreach (e; 0..2) { foreach (f; 0..2) { if (b == 0 || d == 1) { if (P == 8 && c > 0) { ret += dp[M][a][b][c][d][e][f]; ret %= MOD; } else if (P == 80 && (c > 0 || (c == 0 && f != 0))) { ret += dp[M][a][b][c][d][e][f]; ret %= MOD; } else if (P == 800 && (c > 0 || (c == 0 && (e != 0 || f != 0)))) { ret += dp[M][a][b][c][d][e][f]; ret %= MOD; } } } } } } } } return ret; } void main() { auto s = readln.split; auto A = s[0]; auto B = s[1]; auto P = s[2].to!int; auto a = solve(A, P, true); auto b = solve(B, P, false); auto ans = (b - a) % MOD; ans = (ans + MOD) % MOD; ans.writeln; }