#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 5000;
string l, r;
long long dp[N][N], len, m, d, v[N];
long long dfs(int p, long long s, int k) {
  if (p == -1) return s == 0;
  if (k == 0 && dp[p][s] != -1) return dp[p][s];
  int ans = 0, end = k ? v[p] : 9;
  for (int i = 0; i <= end; i++) {
    if ((len - p) % 2 == 0 && i != d) continue;
    if ((len - p) % 2 == 1 && i == d) continue;
    ans = (ans + dfs(p - 1, (s * 10 + i) % m, k && i == v[p]) % mod) % mod;
  }
  if (k == 0) dp[p][s] = ans;
  return ans;
}
long long solve(string x) {
  memset(dp, -1, sizeof(dp));
  len = x.size();
  for (int i = 0; i < len; i++) v[len - i - 1] = x[i] - '0';
  return dfs(len - 1, 0, 1);
}
int checkl() {
  long long ls = l.size(), sum = 0;
  for (int i = 0; i < ls; i++) {
    int x = l[i] - '0';
    if (i % 2 == 0) {
      if (x == d) return 0;
    } else {
      if (x != d) return 0;
    }
    sum = (sum * 10 + x) % m;
  }
  return sum == 0;
}
int main() {
  cin >> m >> d >> l >> r;
  long long ans = solve(r) % mod - solve(l) % mod + checkl();
  printf("%lld", (ans + mod) % mod);
}
