#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& r) {
  r = 0;
  register int f = 1;
  register char ch = getchar();
  while (ch < '0' or ch > '9') {
    f = (ch == '-' ? -1 : 1), ch = getchar();
  }
  while (ch >= '0' and ch <= '9') {
    r = r * 10 + ch - '0', ch = getchar();
  }
  r *= f;
}
int ROW[] = {+0, +0, -1, +1};
int COL[] = {+1, -1, +0, +0};
int X[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int Y[] = {-1, +1, +0, +0, +1, +1, -1, -1};
int KX[] = {-2, -2, -1, -1, 1, 1, 2, 2};
int KY[] = {-1, 1, -2, 2, -2, 2, -1, 1};
string s[3];
long long dp[2002][2002][2];
int m, d;
long long solve(int ind, int pos, int sum, bool flag) {
  if (pos >= s[ind].size()) {
    if (!sum) return 1;
    return 0;
  }
  long long& res = dp[pos][sum][flag];
  if (res != -1) return res;
  res = 0;
  int lim;
  if (flag)
    lim = 9;
  else
    lim = s[ind][pos] - '0';
  if ((pos & 1) && lim < d)
    return res;
  else if ((pos & 1)) {
    res = solve(ind, pos + 1, (sum * 10 + d) % m, d < lim ? true : flag);
    return res;
  }
  for (int i = 0; i < lim; i++) {
    if (i == d) continue;
    res += solve(ind, pos + 1, (sum * 10 + i) % m, true);
    res %= 1000000007;
  }
  if (lim != d) res += solve(ind, pos + 1, (sum * 10 + lim) % m, flag);
  res %= 1000000007;
  return res;
}
bool includable(string str) {
  int num = 0;
  for (int i = 0; i < str.size(); i++) {
    if (i % 2 == 0 && str[i] - '0' == d) return false;
    if (i % 2 == 1 && str[i] - '0' != d) return false;
    num = num * 10 + str[i] - '0';
    num %= m;
  }
  return num % m == 0;
}
int main() {
  long long ans = 0;
  cin >> m >> d >> s[0] >> s[1];
  memset(dp, -1, sizeof dp);
  ;
  ans = solve(0, 0, 0, 0);
  if (includable(s[0])) ans--;
  memset(dp, -1, sizeof dp);
  ;
  cout << (solve(1, 0, 0, 0) - ans + 1000000007) % 1000000007 << endl;
  return 0;
}
