#include <bits/stdc++.h>
using namespace std;
const int N = 2001, M = 1e9 + 7;
char a[N], b[N];
int m, d, n, dp[N][N][2][2];
int calc(int at, int mod, bool A, bool B) {
  if (at == n) return mod == 0 && A && B;
  int &res = dp[at][mod][A][B];
  if (res != -1) return res;
  res = 0;
  if (at & 1) {
    if ((A || d >= (a[at] - '0')) && (B || d <= (b[at] - '0')))
      res = calc(at + 1, (mod * 10 + d) % m, A || (d > (a[at] - '0')),
                 B || (d < (b[at] - '0')));
    return res;
  }
  for (int i = 0; i < 10; ++i) {
    if (i == d) continue;
    if ((A || i >= (a[at] - '0')) && (B || i <= (b[at] - '0')))
      res = (res + calc(at + 1, (mod * 10 + i) % m, A || (i > (a[at] - '0')),
                        B || (i < (b[at] - '0')))) %
            M;
  }
  return res;
}
bool check(char *s) {
  int mod = 0;
  for (int i = 0; i < n; ++i) {
    if ((i & 1) == 1 && (s[i] - '0') != d) return false;
    if ((i & 1) == 0 && (s[i] - '0') == d) return false;
    mod = (mod * 10 + (s[i] - '0')) % m;
  }
  return mod == 0;
}
int main() {
  srand(time(0));
  scanf("%d%d%s%s", &m, &d, a, b);
  memset(dp, -1, sizeof dp);
  n = strlen(a);
  int from = a[0] - '0', to = b[0] - '0';
  int res = 0;
  for (int i = from; i <= to; ++i) {
    if (i == d) continue;
    res = (res + calc(1, i % m, i > from, i < to)) % M;
  }
  if (check(a)) ++res;
  bool ok = true;
  for (int i = 0; i < n && ok; ++i) ok &= a[i] == b[i];
  if (!ok && check(b)) ++res;
  res %= M;
  printf("%d\n", res);
  return 0;
}
