#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  char c = getchar();
  T fh = 0;
  bool f = false;
  while (!isdigit(c)) f |= (c == '-'), c = getchar();
  while (isdigit(c)) fh = (fh << 1) + (fh << 3) + (c ^ 48), c = getchar();
  x = f ? -fh : fh;
  return;
}
char s1[2005], s2[2005];
int m, d, le, ans[2005];
long long dp[2005][2005];
const int mod = 1e9 + 7;
long long dfs(int pos, int mo, bool st, bool lim) {
  if (pos == le) return !mo;
  if (!st && !lim && ~dp[pos][mo]) return dp[pos][mo];
  int sx = lim ? ans[pos] : 9;
  long long res = 0;
  for (int i = (0); i <= (sx); ++i)
    if ((pos % 2 == 0 && i != d) || (pos % 2 && i == d))
      res = (res + dfs(pos + 1, (mo * 10 + i) % m, st && !i, lim && i == sx)) %
            mod;
  if (!st && !lim) dp[pos][mo] = res;
  return res;
}
long long solve(char s[]) {
  memset(dp, -1, sizeof(dp));
  for (int i = (0); i <= (le - 1); ++i) ans[i] = s[i] - '0';
  return dfs(0, 0, 1, 1);
}
int main() {
  read(m), read(d);
  cin >> s1 >> s2;
  int len = strlen(s1) - 1;
  le = len + 1;
  while (s1[len] == '0') s1[len] = '9', --len;
  s1[len]--;
  printf("%lld\n", ((solve(s2) - solve(s1)) % mod + mod) % mod);
  return 0;
}
