#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline int sum(int a, int b, int modulo = mod) { return (a + b) % modulo; }
inline int mult(int a, int b, int modulo = mod) {
  long long val = a * 1LL * b;
  val %= modulo;
  return (int)(val);
}
inline int diff(int a, int b) {
  int res = a - b;
  while (res < 0) res += mod;
  return res;
}
const int N = 2009, A = 2009;
int dp[N][A][2];
int m, d;
string a, b;
inline void update(int &want, int how) { want = sum(want, how); }
inline bool checkPosition(int pos, int x) {
  if (pos % 2 == 0 && x == d) return false;
  if (pos % 2 == 1 && x != d) return false;
  return true;
}
inline int solve(string &s) {
  memset(dp, 0, sizeof(dp));
  int border = s[0] - '0', fin = int(s.size()) - 1;
  for (int a = 1; a <= border; ++a) {
    if (a == d) continue;
    dp[0][a % m][a == border]++;
  }
  for (int i = 0; i < (int)(fin); ++i) {
    for (int a = 0; a < (int)(m); ++a) {
      for (int k = 0; k < (int)(2); ++k) {
        int cur = mult(a, 10, m), was = dp[i][a][k];
        border = s[i + 1] - '0';
        for (int p = 0; p < 10; ++p) {
          if (!checkPosition(i + 1, p)) continue;
          int ost = sum(cur, p, m);
          if (k == 0 || p < border)
            update(dp[i + 1][ost][0], was);
          else if (p == border) {
            update(dp[i + 1][ost][1], was);
          }
        }
      }
    }
  }
  return sum(dp[fin][0][0], dp[fin][0][1]);
}
bool good(string &s) {
  int ost = 0;
  for (int i = 0; i < (int)(int(s.size())); ++i) {
    int cur = s[i] - '0';
    if (!checkPosition(i, cur)) return false;
    ost = mult(ost, 10, m);
    ost = sum(ost, cur, m);
  }
  return (bool)(ost == 0);
}
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(NULL);
  cin >> m >> d;
  cin >> a >> b;
  int ans = diff(solve(b), solve(a));
  ans = sum(ans, good(a));
  cout << ans;
  return 0;
}
