#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2005;
long long dp[N][N][2], len, m, d;
char s[N];
inline long long add(long long x, long long y) { return (x + y) % mod; }
void pre() {
  for (int i = 1; i <= len; ++i) {
    s[i] -= '0';
  }
  memset(dp, -1, sizeof dp);
}
long long solve(long long prevRemainder, int idx, bool canUseAll) {
  if (idx == 0) {
    pre();
    return solve(0, 1, 0);
  }
  if (idx == len + 1) {
    return prevRemainder == 0;
  }
  long long &cur = dp[prevRemainder][idx][canUseAll];
  if (cur != -1) {
    return cur;
  }
  cur = 0;
  long long curRem = prevRemainder * 10;
  if (idx % 2 == 0) {
    if (s[idx] >= d) {
      return cur = add(cur, solve((curRem + d) % m, idx + 1,
                                  canUseAll | (s[idx] > d)));
    } else if (canUseAll) {
      return cur = add(cur, solve((curRem + d) % m, idx + 1, 1));
    }
    return cur;
  }
  if (!canUseAll) {
    long long ref = 0;
    for (int dig = 0; dig < s[idx]; ++dig) {
      if (dig != d) {
        ref = add(ref, solve((curRem + dig) % m, idx + 1, 1));
      }
    }
    if (s[idx] != d) {
      ref = add(ref, solve((curRem + s[idx]) % m, idx + 1, 0));
    }
    return cur = ref;
  }
  long long ref = 0;
  for (int dig = 0; dig <= 9; ++dig) {
    if (dig != d) ref = add(ref, solve((curRem + dig) % m, idx + 1, 1));
  }
  return cur = ref;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> d;
  cin >> s + 1;
  len = strlen(s + 1);
  long long L = solve(0, 0, 0);
  auto check = [&]() {
    int cur = 0;
    for (int i = 1; i <= len; ++i) {
      if (i % 2 == 0 && s[i] != d) {
        return 0;
      }
      if (i % 2 && s[i] == d) return 0;
      cur = (cur * 10 + s[i]) % m;
    }
    if (cur % m == 0) return 1;
    return 0;
  };
  bool f = check();
  cin >> s + 1;
  len = strlen(s + 1);
  long long R = solve(0, 0, 0);
  long long ans = (R - L + f + mod) % mod;
  cout << ans << '\n';
}
