#include <bits/stdc++.h>
using namespace std;
int m, d;
int dp[2100][2100];
int dp1[2100][2100];
int yu[2100];
int a[2100], b[2100];
char s[2100];
int len;
void init() {
  yu[0] = 1;
  for (int i = 1; i <= 2000; i++) {
    yu[i] = yu[i - 1] * 10 % m;
  }
}
void DP() {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i <= 9; i++) {
    if (i == d) continue;
    dp[1][i % m] += 1;
  }
  for (int i = 1; i <= 2010; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k <= 9; k++) {
        if (!(i & 1) && k != d)
          dp[i + 1][(j * 10 + k) % m] += dp[i][j];
        else if (i & 1 && k == d)
          dp[i + 1][(j * 10 + k) % m] += dp[i][j];
        dp[i + 1][(j * 10 + k) % m] %= 1000000007;
      }
    }
  }
}
int calc(int *s) {
  int ans = 0;
  int tmp = 0;
  bool flag = 0;
  for (int i = 1; i <= len; i++) {
    if (i & 1) {
      for (int j = 0; j < s[i] || (flag && j <= 9); j++) {
        if (i == 1 && j == 0) continue;
        if (j == d) continue;
        if (i < len)
          ans +=
              dp[len - i - 1]
                [(-(tmp + j * yu[len - i] + d * yu[len - i - 1]) % m + m) % m];
        else
          ans += dp[len - i][(-(tmp + j * yu[len - i]) % m + m) % m];
        ans %= 1000000007;
      }
      tmp = (tmp + s[i] * yu[len - i]) % m;
      if (s[i] == d) break;
      if (flag) break;
    } else {
      if (s[i] < d && !flag)
        break;
      else if (s[i] == d && i == len)
        break;
      else if (s[i] > d)
        flag = 1;
      if (i == len) ans += dp[len - i][(-(tmp + d * yu[len - i]) % m + m) % m];
      ans %= 1000000007;
      tmp = (tmp + d * yu[len - i]) % m;
    }
  }
  return ans;
}
bool check() {
  int tmp = 0;
  bool flag = 0;
  for (int i = 1; i <= len; i++) {
    if (i & 1 && b[i] == d)
      return false;
    else if (!(i & 1) && b[i] != d)
      return false;
    tmp = tmp * 10 + b[i];
    tmp %= m;
  }
  if (tmp != 0) return false;
  return true;
}
void solve() {
  int ans = 0;
  if (len == 1) {
    for (int i = a[1]; i <= b[1]; i++) {
      if (i == d) continue;
      if (i % m == 0) ans++;
    }
    printf("%d\n", ans);
    return;
  }
  DP();
  ans = calc(b) - calc(a) + check();
  ans = (ans + 1000000007) % 1000000007;
  printf("%d\n", ans);
}
int main() {
  while (scanf("%d%d", &m, &d) != EOF) {
    init();
    scanf("%s", s);
    len = strlen(s);
    for (int i = 0; s[i]; i++) {
      a[i + 1] = s[i] - '0';
    }
    scanf("%s", s);
    for (int i = 0; s[i]; i++) {
      b[i + 1] = s[i] - '0';
    }
    solve();
  }
  return 0;
}
