#include <bits/stdc++.h>
using namespace std;
const int N = 2005, Mod = 1e9 + 7;
inline int add(int a, int b, int mod) {
  return (a + b >= mod) ? a + b - mod : a + b;
}
inline int dec(int a, int b, int mod) {
  return (a - b < 0) ? a - b + mod : a - b;
}
inline int mul(int a, int b, int mod) { return 1ll * a * b % mod; }
int m, d, len;
int num[N];
int f[N][N], Pow[N];
bool vis[N][N];
int dp(int pos, int rem, bool lim) {
  if (pos > len) return rem == 0;
  if (!lim && vis[pos][rem]) return f[pos][rem];
  vis[pos][rem] = 1;
  int ret = 0;
  if (pos & 1) {
    for (int i = 0; i <= (lim ? num[pos] : 9); ++i) {
      if (i == d) continue;
      ret = add(ret,
                dp(pos + 1, add(rem, 1ll * i * Pow[len - pos] % m, m),
                   lim && i == num[pos]),
                Mod);
    }
  } else {
    if (lim && d > num[pos]) return f[pos][rem] = 0;
    ret = add(ret,
              dp(pos + 1, add(rem, 1ll * d * Pow[len - pos] % m, m),
                 lim && d == num[pos]),
              Mod);
  }
  return f[pos][rem] = ret;
}
inline int calc(char *s, bool type) {
  len = strlen(s + 1);
  for (int i = 1; i <= len; ++i) num[i] = s[i] - '0';
  Pow[0] = 1;
  for (int i = 1; i <= len; ++i) Pow[i] = 1ll * Pow[i - 1] * 10 % m;
  if (type)
    for (int i = len; i >= 1; --i)
      if (num[i]) {
        --num[i];
        break;
      } else
        num[i] = 9;
  memset(vis, 0, sizeof(vis));
  return dp(1, 0, 1);
}
char l[N], r[N];
int ans;
int main() {
  scanf("%d %d", &m, &d);
  scanf("%s", l + 1);
  scanf("%s", r + 1);
  ans = calc(r, 0);
  ans = dec(ans, calc(l, 1), Mod);
  printf("%d", ans);
  return 0;
}
