#include <bits/stdc++.h>
using namespace std;
bool pr[1000007];
void sieve() {
  pr[0] = 1;
  pr[1] = 1;
  for (int i = 2; i * i < (1000007); i++) {
    for (int j = 2 * i; j <= 1000007; j += i) {
      pr[j] = 1;
    }
  }
}
vector<int> num;
int m, d;
int dp[2003][2003][2][2];
int get(int pos, int nu, int f2, int flag) {
  if (pos == num.size()) {
    if (f2 && nu == 0) {
      return 1;
    } else
      return 0;
  }
  if (dp[pos][nu][f2][flag] != -1) {
    return dp[pos][nu][f2][flag];
  }
  int lmt;
  int ans = 0;
  if (!flag) {
    lmt = num[pos];
  } else {
    lmt = 9;
  }
  for (int i = 0; i <= lmt; i++) {
    int nf = flag, nf2 = f2;
    ;
    if (!flag && i < lmt) {
      nf = 1;
    }
    if ((pos & 1) && i != d) {
      nf2 = 0;
    }
    if (!(pos & 1) && i == d) {
      nf2 = 0;
    }
    ans =
        (int)(ans + (int)get(pos + 1, (nu * 10 + i) % m, nf2, nf)) % 1000000007;
  }
  return (dp[pos][nu][f2][flag] = ans);
}
int give(string n) {
  num.clear();
  memset(dp, -1, sizeof dp);
  for (auto e : n) {
    num.push_back(e - 48);
  }
  int ans = get(0, 0, 1, 0);
  return ans;
}
int mod(string num, int a) {
  int res = 0;
  for (int i = 0; i < num.length(); i++)
    res = (res * 10 + (int)num[i] - '0') % a;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> d;
  int t = 1;
  while (t--) {
    string a, b;
    cin >> a >> b;
    int pos = 0, f = 1;
    vector<int> pk;
    for (auto e : a) {
      if (e == char(d + 48)) pk.push_back(pos);
      if (pos & 1) {
        if (e != char(d + 48)) {
          f = 0;
          break;
        }
      }
      pos++;
    }
    for (auto e : pk) {
      if (!(e & 1)) {
        f = 0;
        break;
      }
    }
    if (mod(a, m) != 0) {
      f = 0;
    }
    cout << (((give(b) - give(a)) + 1000000007) % 1000000007 + f) % 1000000007
         << "\n";
  }
}
