#include <bits/stdc++.h>
const double EPS = 0.00000001;
const long long mod = 1000000000 + 7;
using namespace std;
string a, b;
int m, d, n;
long long dp[2001][2001][2][2];
long long f(int i, int x, int lo, int hi) {
  if (i == n) {
    if (x == 0) return 1;
    return 0;
  }
  if (i == a.size()) lo = 0;
  if (dp[i][x][lo][hi] != -1) return dp[i][x][lo][hi];
  long long ans = 0;
  if (i % 2) {
    long long y = (x * 10 + d) % m;
    if (hi) {
      if (lo) {
        if (d < a[i] - '0' || d > b[i] - '0') return 0;
        if (d == a[i] - '0' && d == b[i] - '0')
          ans = f(i + 1, y, 1, 1);
        else if (d == a[i] - '0' && d < b[i] - '0')
          ans = f(i + 1, y, 1, 0);
        else if (d > a[i] - '0' && d == b[i] - '0')
          ans = f(i + 1, y, 0, 1);
        else
          ans = f(i + 1, y, 0, 0);
      } else {
        if (b[i] - '0' < d)
          return 0;
        else if (b[i] - '0' == d)
          ans = f(i + 1, (x * 10 + d) % m, lo, 1);
        else {
          ans = f(i + 1, (x * 10 + d) % m, lo, 0);
        }
      }
    } else {
      if (lo) {
        if (d < a[i] - '0') return 0;
        if (d == a[i] - '0')
          ans = f(i + 1, y, 1, 0);
        else
          ans = f(i + 1, y, 0, 0);
      } else {
        ans = f(i + 1, y, 0, 0);
      }
    }
  } else {
    if (lo) {
      if (hi) {
        for (int j = a[i] - '0'; j <= b[i] - '0'; j++) {
          if (j == d) continue;
          long long y = (x * 10 + j) % m;
          if (j == a[i] - '0' && j == b[i] - '0')
            ans = (ans + f(i + 1, y, 1, 1)) % mod;
          else if (j == a[i] - '0' && j < b[i] - '0')
            ans = (ans + f(i + 1, y, 1, 0)) % mod;
          else if (j > a[i] - '0' && j == b[i] - '0')
            ans = (ans + f(i + 1, y, 0, 1)) % mod;
          else
            ans = (ans + f(i + 1, y, 0, 0)) % mod;
        }
      } else {
        for (int j = a[i] - '0'; j <= 9; j++) {
          if (j == d) continue;
          long long y = (x * 10 + j) % m;
          if (j == a[i] - '0')
            ans = (ans + f(i + 1, y, 1, 0)) % mod;
          else
            ans = (ans + f(i + 1, y, 0, 0)) % mod;
        }
      }
    } else {
      if (hi) {
        for (int j = 0; j <= b[i] - '0'; j++) {
          if (j == d) continue;
          long long y = (x * 10 + j) % m;
          if (j == b[i] - '0')
            ans = (ans + f(i + 1, y, 0, 1)) % mod;
          else
            ans = (ans + f(i + 1, y, 0, 0)) % mod;
        }
      } else {
        for (int j = 0; j <= 9; j++) {
          if (j == d) continue;
          ans = (ans + f(i + 1, (x * 10 + j) % m, 0, 0)) % mod;
        }
      }
    }
  }
  return dp[i][x][lo][hi] = ans;
}
int main() {
  cin >> m >> d >> a >> b;
  memset(dp, -1, sizeof(dp));
  n = b.size();
  cout << f(0, 0, 1, 1) << endl;
  int ____________;
  cin >> ____________;
  return 0;
}
