#include using namespace std; using lint = long long int; template using V = vector; template using VV = V< V >; template void assign(V& v, int n, const T& a = T()) { v.assign(n, a); } template void assign(V& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); } const lint mod = 1e9 + 7; inline lint emod(lint a, lint p = mod) { return (a % p + p) % p; } int main() { cin.tie(NULL); ios::sync_with_stdio(false); string a, b; cin >> a >> b; int p; cin >> p; auto calc = [&](string x, int in) { x = "00" + x; int n = x.size(); VV>> dp; assign(dp, 4, 2, 3, 2, 8); dp[0][1][0][0][0] = 1; for (int i = 0; i < n; i++) { assign(dp[i + 1 & 3], 2, 3, 2, 8, 0LL); for (int r = 0; r < 3; r++) for (int s = 0; s < 8; s++) for (int d = 0; d < 10; d++) { (dp[i + 1 & 3][0][(r + d) % 3][d == 3][2 * s + d & 7] += dp[i & 3][0][r][0][s]) %= mod; (dp[i + 1 & 3][0][(r + d) % 3][1][2 * s + d & 7] += dp[i & 3][0][r][1][s]) %= mod; if (d > x[i] - '0') continue; (dp[i + 1 & 3][d == x[i] - '0'][(r + d) % 3][d == 3][2 * s + d & 7] += dp[i & 3][1][r][0][s]) %= mod; (dp[i + 1 & 3][d == x[i] - '0'][(r + d) % 3][1][2 * s + d & 7] += dp[i & 3][1][r][1][s]) %= mod; } } lint res = 0; for (int f = 0; f < 2; f++) for (int r = 0; r < 3; r++) for (int g = 0; g < 2; g++) for (int s = 0; s < 8; s++) { if (p == 8) { if (f <= in and (!r or g) and s) (res += dp[n & 3][f][r][g][s]) %= mod; } else if (p == 80) { if (f <= in and (!r or g)) (res += dp[n & 3][f][r][g][s]) %= mod; if (f <= in and (!r or g) and !s) (res -= dp[n - 1 & 3][f][r][g][s]) %= mod; } else { if (f <= in and (!r or g)) (res += dp[n & 3][f][r][g][s]) %= mod; if (f <= in and (!r or g) and !s) (res -= dp[n - 2 & 3][f][r][g][s]) %= mod; } } return res; }; cout << emod(calc(b, 1) - calc(a, 0)) << '\n'; }