#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigMod(T p, T e, T M) {
  T ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T modInverse(T a, T M) {
  return bigMod(a, M - 2, M);
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T>
inline T SQR(T a) {
  return a * a;
}
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
long long int dp[2000][2000][2][2], d, m;
string a, b;
void init() {
  for (int i = int(0); i < int(2000); i++)
    for (int j = int(0); j < int(2000); j++)
      for (int k = int(0); k < int(2); k++)
        for (int l = int(0); l < int(2); l++) dp[i][j][k][l] = -1;
}
long long int digdp(int pos, int num, bool small, bool large) {
  if (pos == a.length()) return num % m == 0;
  if (dp[pos][num][small][large] != -1)
    return dp[pos][num][small][large] % 1000000007;
  long long int ret = 0;
  if (pos % 2) {
    if ((small or d <= (b[pos] - '0')) and (large or d >= (a[pos] - '0'))) {
      ret += digdp(pos + 1, (num * 10 + d) % m, small or d < (b[pos] - '0'),
                   large or d > (a[pos] - '0')) %
             1000000007;
      ret %= 1000000007;
    }
    return dp[pos][num][small][large] = ret % 1000000007;
  }
  for (int i = 0; i < 10; i++) {
    if (i == d) continue;
    if ((small or i <= (b[pos] - '0')) and (large or i >= (a[pos] - '0'))) {
      ret += digdp(pos + 1, (num * 10 + i) % m, small or i < (b[pos] - '0'),
                   large or i > (a[pos] - '0')) %
             1000000007;
      ret %= 1000000007;
    }
  }
  return dp[pos][num][small][large] = ret % 1000000007;
}
int main() {
  scanf("%lld %lld", &m, &d);
  cin >> a >> b;
  init();
  printf("%lld", digdp(0, 0, 0, 0));
  printf("\n");
  return 0;
}
