#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long dp[2005][2005][2];
long long m, d;
long long n;
string a, b;
vector<long long> digits;
long long calc(long long i, long long j, long long ok) {
  if (dp[i][j][ok] != -1) return dp[i][j][ok];
  if (i == n) {
    if (j != 0) return 0;
    return 1;
  }
  long long lim = 9;
  if (not ok) lim = digits[i];
  long long ret = 0;
  for (long long num = 0; num <= lim; ++num) {
    if (((i + 1) & 1) && num == d) continue;
    if ((not((i + 1) & 1)) && num != d) continue;
    long long new_ok = ok;
    if (num < lim) new_ok = 1;
    long long new_rem = (j * 10 + num) % m;
    ret = (ret + calc(i + 1, new_rem, new_ok)) % mod;
  }
  return (dp[i][j][ok] = ret);
}
inline void init(const string& s) {
  for (long long i = 0; i < 2005; ++i) {
    for (long long j = 0; j < 2005; ++j) {
      for (long long k = 0; k < 2; ++k) {
        dp[i][j][k] = -1;
      }
    }
  }
  digits.clear();
  digits.resize((long long)s.size());
  for (long long i = 0; i < (long long)s.size(); ++i) digits[i] = s[i] - '0';
  n = (long long)digits.size();
}
inline long long solve(const string& s) {
  init(s);
  return calc(0, 0, 0);
}
bool isDMagic(const string& s) {
  long long rem = 0;
  for (long long i = 0; i < (long long)s.size(); ++i) {
    rem = (rem * 10 + (s[i] - '0')) % m;
    if ((i + 1) & 1 && (s[i] - '0') == d) return false;
    if (not((i + 1) & 1) && (s[i] - '0') != d) return false;
  }
  if (rem) return false;
  return true;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> d;
  cin >> a >> b;
  long long ans = solve(b) - solve(a);
  if (isDMagic(a)) ++ans;
  cout << ((ans % mod) + mod) % mod;
  return 0;
}
