#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
bool chmin(T1 &a, T2 b) {
  return b < a && (a = b, true);
}
template <class T1, class T2>
bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
const long long mod = 1e9 + 7;
int m, D;
long long solve(string s, bool less) {
  static long long dp0[2][2][2020], dp1[2][2][2020];
  memset(dp0, 0, sizeof(dp0));
  memset(dp1, 0, sizeof(dp1));
  dp0[0][0][0] = 1;
  int n = s.size();
  for (int i = 0; i < (n); i++) {
    memset(dp1, 0, sizeof(dp1));
    for (int j = 0; j < (2); j++)
      for (int k = 0; k < (2); k++)
        for (int l = 0; l < (m); l++) {
          int lim = j ? 9 : s[i] - '0';
          for (int d = 0; d < (lim + 1); d++) {
            if (d != 0 || k) {
              if (i % 2 == 1 && d != D) continue;
              if (i % 2 == 0 && d == D) continue;
            }
            (dp1[j || d < lim][k || d != 0][(l * 10 + d) % m] +=
             dp0[j][k][l]) %= mod;
          }
        }
    swap(dp0, dp1);
  }
  long long ret = 0;
  for (int j = 0; j < (2); j++)
    for (int k = 0; k < (2); k++)
      if (j || !less) (ret += dp0[j][k][0]) %= mod;
  return ret;
}
int main() {
  cin >> m >> D;
  string a, b;
  cin >> a >> b;
  long long ans = solve(b, false) - solve(a, true);
  ans = (ans % mod + mod) % mod;
  cout << ans << endl;
  return 0;
}
