#include <bits/stdc++.h>
using namespace std;
void XsliferX() {
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}
long long f_p(long long x, int y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return f_p((x * x), y / 2);
  else
    return (x * f_p((x * x), y / 2));
}
int dx[9] = {1, -1, 0, 0, 0, 1, -1, 1, -1};
int dy[9] = {0, 0, 1, -1, 0, 1, -1, -1, 1};
int m, d;
string a, b;
const int N = 2002;
long long dp[N][N][2];
int solve(string s) {
  int n = s.size();
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      for (int k = 0; k < 2; k++) dp[i][j][k] = 0;
  dp[0][0][1] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      for (int k = 0; k < 2; k++)
        for (int p = 0; p <= (k ? int(s[i] - '0') : 9); p++) {
          if ((i & 1) && p != d) continue;
          if (!(i & 1) && p == d) continue;
          if (!i && !p) continue;
          int ni = i + 1;
          int nj = (j * 10 + p) % m;
          int nk = k && (p == int(s[i] - '0'));
          dp[ni][nj][nk] += dp[i][j][k];
          dp[ni][nj][nk] %= 1000000007;
        }
  return (dp[n][0][0] + dp[n][0][1]) % 1000000007;
}
bool good(string s) {
  int rm = 0;
  for (int i = 0; i < s.size(); i++) {
    int p = int(s[i] - '0');
    if ((i & 1) && p != d) return false;
    if (!(i & 1) && p == d) return false;
    rm = (rm * 10 + p) % m;
  }
  return !rm;
}
int main() {
  XsliferX();
  cin >> m >> d;
  cin >> a >> b;
  cout << ((solve(b) - solve(a)) + 1000000007 + good(a)) % 1000000007;
  return 0;
}
