#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
int m, d, l, a[2010];
long long f[3][2010][2], ans;
char s[2010];
void turn() {
  l = strlen(s + 1);
  for (int i = 1; i <= l; i++) {
    a[i] = s[i] - '0';
  }
}
bool check() {
  int x = 0;
  for (int i = 1; i <= l; i++) {
    if (!(i & 1) && a[i] != d) {
      return false;
    }
    if ((i & 1) && a[i] == d) {
      return false;
    }
    x = (x * 10 + a[i]) % m;
  }
  return x == 0;
}
void clear(int t) {
  for (int i = 0; i < m; i++) {
    f[t][i][0] = f[t][i][1] = 0;
  }
}
void upd(long long &x, long long v) { x = (x + v) % Mod; }
long long work() {
  int p = 2, np = 0, lp = 1, nxt;
  clear(p);
  clear(np);
  clear(lp);
  if (l > 1) {
    if (a[1] != d) {
      nxt = (a[1] * 10 + d) % m;
      if (a[2] == d) {
        upd(f[lp][nxt][1], 1);
      }
      if (a[2] > d) {
        upd(f[lp][nxt][0], 1);
      }
    }
    for (int k = 1; k < a[1]; k++) {
      if (k == d) {
        continue;
      }
      nxt = (k * 10 + d) % m;
      upd(f[lp][nxt][0], 1);
    }
  } else {
    for (int k = 1; k <= a[1]; k++) {
      if (k == d) {
        continue;
      }
      nxt = k % m;
      upd(f[np][nxt][0], 1);
    }
  }
  for (int i = 2; i <= l; i++) {
    lp = p;
    p = np;
    np = (np + 1) % 3;
    for (int j = 0; j < m; j++) {
      if (i < l) {
        if (f[p][j][1]) {
          if (a[i] != d) {
            nxt = (j * 100 + a[i] * 10 + d) % m;
            if (a[i + 1] == d) {
              upd(f[lp][nxt][1], f[p][j][1]);
            } else if (a[i + 1] > d) {
              upd(f[lp][nxt][0], f[p][j][1]);
            }
          }
          for (int k = 0; k < a[i]; k++) {
            if (k == d) {
              continue;
            }
            nxt = (j * 100 + k * 10 + d) % m;
            upd(f[lp][nxt][0], f[p][j][1]);
          }
        }
        if (f[p][j][0]) {
          for (int k = 0; k < 10; k++) {
            if (k == d) {
              continue;
            }
            nxt = (j * 100 + k * 10 + d) % m;
            upd(f[lp][nxt][0], f[p][j][0]);
          }
        }
      } else {
        if (f[p][j][1]) {
          for (int k = 0; k <= a[i]; k++) {
            if (k == d) {
              continue;
            }
            nxt = (j * 10 + k) % m;
            upd(f[np][nxt][0], f[p][j][1]);
          }
        }
        if (f[p][j][0]) {
          for (int k = 0; k < 10; k++) {
            if (k == d) {
              continue;
            }
            nxt = (j * 10 + k) % m;
            upd(f[np][nxt][0], f[p][j][0]);
          }
        }
      }
    }
    if (i < l) {
      for (int k = 1; k < 10; k++) {
        if (k == d) {
          continue;
        }
        nxt = (k * 10 + d) % m;
        upd(f[lp][nxt][0], 1);
      }
    } else {
      for (int k = 1; k < 10; k++) {
        if (k == d) {
          continue;
        }
        nxt = k % m;
        upd(f[np][nxt][0], 1);
      }
    }
    clear(p);
  }
  return (f[np][0][0] + f[np][0][1]) % Mod;
}
int main() {
  scanf("%d%d", &m, &d);
  scanf("%s", s + 1);
  turn();
  if (check()) {
    ans++;
  }
  ans = (ans - work() + Mod) % Mod;
  scanf("%s", s + 1);
  turn();
  ans = (ans + work()) % Mod;
  cout << ans << endl;
  return 0;
}
