#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
const int MOD = 1e9 + 7;
int m, d, n, f[N][2][2][N];
string a, b;
void inp() {
  cin >> m >> d;
  cin >> a >> b;
}
void init() {
  n = a.size();
  a = "0" + a;
  b = "0" + b;
  memset(f, -1, sizeof(f));
}
int dp(int pos, bool fa, bool fb, int num) {
  num %= m;
  if (pos == n + 1) {
    if (num % m == 0) return 1;
    return 0;
  }
  if (f[pos][fa][fb][num] != -1) return f[pos][fa][fb][num];
  int res = 0;
  if (pos % 2 == 0) {
    int low = 0, high = 9;
    if (fa) low = a[pos] - '0';
    if (fb) high = b[pos] - '0';
    if (low > d || d > high) return 0;
    bool tfa = false, tfb = false;
    if (d == a[pos] - '0' && fa) tfa = true;
    if (d == b[pos] - '0' && fb) tfb = true;
    res = (res + dp(pos + 1, tfa, tfb, (num * 10 + d) % m)) % MOD;
  } else {
    int low = 0, high = 9;
    if (fa) low = a[pos] - '0';
    if (fb) high = b[pos] - '0';
    for (int i = low; i <= high; i++) {
      if (i == d) continue;
      bool tfa = false, tfb = false;
      if (i == low && fa) tfa = true;
      if (i == high && fb) tfb = true;
      res = (res + dp(pos + 1, tfa, tfb, (num * 10 + i) % m)) % MOD;
    }
  }
  f[pos][fa][fb][num] = res;
  return res;
}
void out() { cout << dp(1, true, true, 0); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  inp();
  init();
  out();
}
