#include <bits/stdc++.h>
using namespace std;
inline bool isLow(char ch) {
  if (ch >= 'a' && ch <= 'z') return true;
  return false;
}
inline bool isUpp(char ch) {
  if (ch >= 'A' && ch <= 'Z') return true;
  return false;
}
inline bool isDig(char ch) {
  if (ch >= '0' && ch <= '9') return true;
  return false;
}
inline bool are_equal(double a, double b) {
  return fabs(a - b) < numeric_limits<double>::epsilon();
}
inline bool less_than(double a, double b) {
  return (b - a) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) *
                    numeric_limits<double>::epsilon());
}
inline bool greater_than(double a, double b) {
  return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) *
                    numeric_limits<double>::epsilon());
}
template <typename T>
string toString(T x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
template <typename T>
T stringToT(string s, T a) {
  T p;
  istringstream ss(s);
  ss >> p;
  return p;
}
template <typename T>
T SOD(T n) {
  __typeof(n) sum = 0, i = 1;
  for (; i * i <= n; i++)
    sum += (n % i) ? 0 : ((((i) * (i)) == n) ? i : i + n / i);
  return sum;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
  for (auto it : v) os << it.first << " : " << it.second << '\n';
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  os << "[";
  for (auto it : v) {
    os << it;
    if (it != *v.rbegin()) os << ", ";
  }
  os << "]";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  for (int i = 0; i < v.size(); i++) {
    os << v[i];
    if (i != (int)v.size() - 1) os << ", ";
  }
  os << "]";
  return os;
}
const int mod = 1e9 + 7;
const int mx = 2 * 100001;
int m, d;
string a, b, inp;
long long dp[2001][2][2001];
long long fun(int i, int t, int v) {
  if (i == inp.size()) return v == 0;
  if (dp[i][t][v] != -1) return dp[i][t][v];
  long long ans = 0, nt = t ? 9 : inp[i] - '0';
  for (int j = 0; j <= nt; j++)
    if ((i & 1) && j == d)
      ans = (ans + fun(i + 1, t | (j < nt), (v * 10 + j) % m)) % mod;
    else if (!(i & 1) && j != d)
      ans = (ans + fun(i + 1, t | (j < nt), (v * 10 + j) % m)) % mod;
  return dp[i][t][v] = ans;
}
long long ok() {
  int v = 0;
  for (int i = 0; i < a.size(); i++)
    if ((i & 1) && a[i] - '0' != d)
      return 0;
    else if (!(i & 1) && a[i] - '0' == d)
      return 0;
    else
      v = (v * 10 + (a[i] - '0')) % m;
  return v == 0;
}
long long solve() {
  cin >> m >> d;
  cin >> a >> b;
  memset(dp, -1, sizeof(dp));
  inp = a;
  long long ans1 = fun(0, 0, 0);
  memset(dp, -1, sizeof(dp));
  inp = b;
  long long ans2 = fun(0, 0, 0);
  return (ans2 - ans1 + ok() + mod) % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << solve() << '\n';
  return 0;
}
