#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long DP[2018][2018][2], bit[2018];
int len, m, k;
string s;
long long Digit_Dp(int pos, int rem, int f) {
  if (pos == s.size()) return (rem == 0);
  if (DP[pos][rem][f] != -1) return DP[pos][rem][f];
  int limit = 0;
  if (f)
    limit = bit[pos];
  else
    limit = 9;
  long long ans = 0;
  for (int i = 0; i <= limit; i++) {
    if (pos % 2 == 0 and i == k) continue;
    if (pos % 2 == 1 and i != k) continue;
    ans += Digit_Dp(pos + 1, (rem * 10 + i) % m, f && (i == limit));
    ans %= MOD;
  }
  return DP[pos][rem][f] = ans;
}
long long get() {
  for (int i = 0; i < s.size(); i++) bit[i] = s[i] - '0';
  return Digit_Dp(0, 0, 1);
}
int Reminder() {
  int t = 0;
  for (int i = 0; i < s.size(); i++) {
    if (i % 2 == 0 && bit[i] == k) return 0;
    if (i % 2 == 1 && bit[i] != k) return 0;
    t = t * 10 + bit[i];
    t %= m;
  }
  if (t == 0)
    return 1;
  else
    return 0;
}
int main() {
  cin >> m >> k;
  long long ans = 0;
  memset(DP, -1, sizeof DP);
  cin >> s;
  long long a = get();
  ans += Reminder();
  cin >> s;
  memset(DP, -1, sizeof DP);
  long long b = get();
  ans += b - a;
  ans = (ans + MOD) % MOD;
  cout << ans << endl;
}
