#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const int INF = 2000000000;
const long long LINF = 2000000000000000000;
template <typename T>
void print(vector<T>& a) {
  for (int i = 0; i < a.size(); i++) cout << a[i] << ' ';
  cout << '\n';
}
template <typename T>
void print(deque<T>& a) {
  for (int i = 0; i < a.size(); i++) cout << a[i] << ' ';
  cout << '\n';
}
template <typename T>
void print(vector<vector<T>>& a) {
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < a[i].size(); j++) cout << a[i][j] << ' ';
    cout << '\n';
  }
}
template <typename T>
void input(vector<T>& a) {
  for (int i = 0; i < a.size(); i++) cin >> a[i];
}
template <typename T>
void input(deque<T>& a) {
  for (int i = 0; i < a.size(); i++) cin >> a[i];
}
template <typename T>
void input(vector<vector<T>>& a) {
  for (int i = 0; i < a.size(); i++)
    for (int j = 0; j < a[i].size(); j++) cin >> a[i][j];
}
const long long mod = 1e9 + 7;
vector<int> num;
long long dp[2020][2020][2];
int m, d;
long long go(int pos, int rem, int f) {
  if (pos == num.size()) return rem == 0;
  if (dp[pos][rem][f] != -1) return dp[pos][rem][f] % mod;
  long long res = 0;
  if (pos == 0) {
    for (int dgt = 1; dgt <= num[pos]; dgt++) {
      if (dgt == d) continue;
      int nf = f;
      if (f == 0 && dgt < num[pos]) nf = 1;
      res += go(pos + 1, (rem * 10 + dgt) % m, nf);
      res %= mod;
    }
    return dp[pos][rem][f] = res % mod;
  }
  if (pos & 1)
    if (f == 0 && d > num[pos])
      return 0;
    else {
      int nf = f;
      if (f == 0 && d < num[pos]) nf = 1;
      res += go(pos + 1, (rem * 10 + d) % m, nf);
      res %= mod;
    }
  else {
    int bound = (f ? 9 : num[pos]);
    for (int dgt = 0; dgt <= bound; dgt++) {
      if (dgt == d) continue;
      int nf = f;
      if (f == 0 && dgt < num[pos]) nf = 1;
      res += go(pos + 1, (rem * 10 + dgt) % m, nf);
      res %= mod;
    }
  }
  return dp[pos][rem][f] = res % mod;
}
long long calc(vector<int> a) {
  num = a;
  memset(dp, -1, sizeof(dp));
  return go(0, 0, 0) % mod;
}
long long check(vector<int> a) {
  int cur = 0;
  int idx = 0;
  for (auto to : a) {
    cur = (cur * 10 + to) % m;
    if ((idx & 1) && to != d || (idx % 2 == 0) && to == d) return 0;
    idx++;
  }
  return cur == 0;
}
void solve() {
  cin >> m >> d;
  string a, b;
  cin >> a >> b;
  vector<int> aa, bb;
  for (auto to : a) aa.push_back(to - '0');
  for (auto to : b) bb.push_back(to - '0');
  long long ans = calc(bb) - calc(aa);
  ans = (ans + mod * mod) % mod;
  ans += check(aa);
  cout << ans % mod;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tst = 1;
  while (tst--) solve();
}
