#include <bits/stdc++.h>
using namespace std;
void read_file(bool outToFile = true) {}
int m, d;
string a, b;
vector<int> A, B;
int n;
int memo[2000][2000][2][2];
int mem[1][1][2][2][2][2];
int rec(int i, int r, bool ea, bool eb, bool beg, bool par) {
  if (i == n) return r == 0;
  int &ret = mem[i][r][ea][eb][beg][par];
  if (ret != -1) return ret;
  ret = 0;
  if (beg) {
    int mna = 0;
    if (ea) mna = A[i];
    int mxa = 9;
    int mnb = 0;
    int mxb = 9;
    if (eb) mxb = B[i];
    int mn = max(mna, mnb);
    int mx = min(mxa, mxb);
    for (int j = mn; j <= mx; j++) {
      if (j == d || j == 0) continue;
      int ni = (i + 1);
      int nr = (r * 10 + j) % m;
      int nea = ea;
      if (j > A[i]) nea = 0;
      int neb = eb;
      if (j < B[i]) neb = 0;
      bool nbeg = beg;
      if (j != 0) nbeg = 0;
      int npar = par;
      if (beg && !nbeg) npar = i % 2;
      ret += rec(ni, nr, nea, neb, nbeg, npar);
      ret %= (1000000007);
    }
    if (mn <= 0 && 0 <= mx) {
      int nea;
      if (ea && 0 == A[i])
        nea = 1;
      else
        nea = 0;
      int neb;
      if (eb && 0 == B[i])
        neb = 1;
      else
        neb = 0;
      ret += rec(i + 1, r, nea, neb, beg, par);
      ret %= (1000000007);
    }
  } else if (i % 2 == par) {
    int mna = 0;
    if (ea) mna = A[i];
    int mxa = 9;
    int mnb = 0;
    int mxb = 9;
    if (eb) mxb = B[i];
    int mn = max(mna, mnb);
    int mx = min(mxa, mxb);
    for (int j = mn; j <= mx; j++) {
      if (j == d) continue;
      int ni = (i + 1);
      int nr = (r * 10 + j) % m;
      int nea = ea;
      if (j > A[i]) nea = 0;
      int neb = eb;
      if (j < B[i]) neb = 0;
      bool nbeg = beg;
      if (j != 0) nbeg = 0;
      int npar = par;
      if (beg && !nbeg) npar = i % 2;
      ret += rec(ni, nr, nea, neb, nbeg, npar);
      ret %= (1000000007);
    }
  } else {
    if (!ea && !eb)
      ret = rec(i + 1, (r * 10 + d) % m, ea, eb, beg, par);
    else if (ea && !eb) {
      if (d >= A[i])
        ret = rec(i + 1, (r * 10 + d) % m, d == A[i], eb, beg, par);
      else
        ret = 0;
    } else if (!ea && eb) {
      if (d <= B[i])
        ret = rec(i + 1, (r * 10 + d) % m, ea, d == B[i], beg, par);
      else
        ret = 0;
    } else {
      if (A[i] <= d && d <= B[i])
        ret = rec(i + 1, (r * 10 + d) % m, d == A[i], d == B[i], beg, par);
      else
        ret = 0;
    }
  }
  return ret;
}
int rec(int i, int r, bool ea, bool eb) {
  if (i == n) return r == 0;
  int &ret = memo[i][r][ea][eb];
  if (ret != -1) return ret;
  ret = 0;
  if (i % 2 == 0) {
    int mna = 0;
    if (ea) mna = A[i];
    int mxa = 9;
    int mnb = 0;
    int mxb = 9;
    if (eb) mxb = B[i];
    int mn = max(mna, mnb);
    int mx = min(mxa, mxb);
    for (int j = mn; j <= mx; j++) {
      if (j == d) continue;
      int ni = (i + 1);
      int nr = (r * 10 + j) % m;
      int nea = ea;
      if (j > A[i]) nea = 0;
      int neb = eb;
      if (j < B[i]) neb = 0;
      ret += rec(ni, nr, nea, neb);
      ret %= (1000000007);
    }
  } else {
    if (!ea && !eb)
      ret = rec(i + 1, (r * 10 + d) % m, ea, eb);
    else if (ea && !eb) {
      if (d >= A[i])
        ret = rec(i + 1, (r * 10 + d) % m, d == A[i], eb);
      else
        ret = 0;
    } else if (!ea && eb) {
      if (d <= B[i])
        ret = rec(i + 1, (r * 10 + d) % m, ea, d == B[i]);
      else
        ret = 0;
    } else {
      if (A[i] <= d && d <= B[i])
        ret = rec(i + 1, (r * 10 + d) % m, d == A[i], d == B[i]);
      else
        ret = 0;
    }
  }
  return ret;
}
vector<int> to_vec(string x) {
  vector<int> ret;
  int m = x.size();
  for (int i = 0; i < n - m; i++) ret.push_back(0);
  for (int i = 0; i < x.size(); i++) ret.push_back(x[i] - '0');
  return ret;
}
int main() {
  read_file();
  while (cin >> m >> d) {
    cin >> a >> b;
    n = a.size();
    A = to_vec(a);
    B = to_vec(b);
    memset(memo, -1, sizeof memo);
    int ans = rec(0, 0, 1, 1);
    cout << ans << '\n';
  }
}
