#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 + 7;
int len, num[2003], f[2003][2003];
long long m, d, ans;
string L, R;
int dfs(int pos, int rem, bool lim) {
  if (!pos) return !rem;
  if (!lim && ~f[pos][rem]) return f[pos][rem];
  int mx = lim ? num[pos] : 9, ans = 0;
  for (int i = 0; i <= mx; ++i) {
    if ((len - pos) & 1) {
      if (i != d) continue;
    } else if (i == d)
      continue;
    ans = ((long long)ans + dfs(pos - 1, (rem * 10 + i) % m, lim && i == mx)) %
          mod;
  }
  if (!lim) f[pos][rem] = ans;
  return ans;
}
inline int work(const string &s) {
  len = s.size();
  for (int i = 0; i <= len - 1; ++i) num[len - i] = s[i] - '0';
  return dfs(len, 0, 1);
}
inline bool check(const string &s) {
  int rem = 0;
  len = s.size();
  for (int pos = 0; pos <= len - 1; ++pos) {
    int i = s[pos] - '0';
    if (pos & 1) {
      if (i != d) return 0;
    } else if (i == d)
      return 0;
    rem = (rem * 10 + i) % m;
  }
  return !rem;
}
int main() {
  memset(f, -1, sizeof f);
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> m >> d >> L >> R;
  ans = work(R) - work(L);
  ans = (((long long)ans + check(L)) % mod + mod) % mod;
  cout << ans;
  return 0;
}
