#include <bits/stdc++.h>
using namespace std;
int const bound = 2e6 + 2, N = 2e5 + 2;
long long OO = 1e18;
double eps = 1e-6;
int oo = 1e9, mod = oo + 7;
int m, d, dp[2001][2001][2][2];
string a, b;
vector<int> ee;
int rec(int r, int p, int g, int ch) {
  int &ret = dp[r][p][g][ch];
  if (ret != -1) return ret;
  ret = 0;
  if (p == (int)ee.size()) return ret = r == 0;
  if (ch) {
    for (int(i) = 0; (i) < (10); (i)++) {
      if (i == d) continue;
      if (g || i < ee[p])
        ret = ret + rec((r * 10 + i) % m, p + 1, 1, !ch);
      else if (i == ee[p])
        ret = ret + rec((r * 10 + i) % m, p + 1, g, !ch);
      if (ret > mod) ret -= mod;
    }
  } else {
    if (g || d == ee[p])
      ret = ret + rec((r * 10 + d) % m, p + 1, g, !ch);
    else if (d < ee[p])
      ret = ret + rec((r * 10 + d) % m, p + 1, 1, !ch);
    if (ret > mod) ret -= mod;
  }
  return ret;
}
int calc() {
  memset(dp, -1, sizeof dp);
  int r = 0;
  for (int i = 1; i < (int)ee.size(); i++) {
    for (int j = 1; j <= 9; j++) {
      if (j == d) continue;
      r = r + rec(j % m, i + 1, 1, 0);
      if (r > mod) r -= mod;
    }
  }
  for (int j = 1; j <= ee[0]; j++) {
    if (j == d) continue;
    r = r + rec(j % m, 1, j < ee[0], 0);
    if (r > mod) r -= mod;
  }
  return r;
}
int main() {
  cin >> m >> d >> a >> b;
  for (int(i) = 0; (i) < (b.size()); (i)++) ee.push_back(b[i] - '0');
  int r = calc();
  ee = vector<int>();
  for (int(i) = 0; (i) < (a.size()); (i)++) ee.push_back(a[i] - '0');
  int l = calc();
  int md = 0, ok = 1;
  for (int i = 0; i < (int)a.size(); i++) {
    if (i % 2 == 1) {
      if (a[i] - '0' != d) ok = 0;
    } else if (a[i] - '0' == d)
      ok = 0;
    md = md * 10 + a[i] - '0';
    md %= m;
  }
  r += (ok && md == 0);
  r -= l;
  r += mod;
  r %= mod;
  cout << r << endl;
  return 0;
}
