#include <bits/stdc++.h>
const int MAX_N = 2123;
const double eps = 1e-6;
const int mod = (int)1e9 + 7;
using namespace std;
int m, dig;
int len;
int pw[MAX_N], dp[MAX_N][10][MAX_N];
void add(int &a, const int &b) {
  a += b;
  if (a >= mod) a -= mod;
}
void init() {
  pw[0] = 1;
  for (int i = 1; i <= len; i++) pw[i] = pw[i - 1] * 10 % m;
  for (int i = len - 1, j = 0; i >= 0; i--, j++) {
    for (int last = 0; last < 10; last++) {
      if (i % 2 == 1 && last != dig) continue;
      if (i % 2 == 0 && last == dig) continue;
      if (i == len - 1) {
        dp[i][last][pw[j] * last % m]++;
        continue;
      }
      for (int prev = 0; prev < 10; prev++)
        for (int modulo = 0; modulo < m; modulo++)
          if (dp[i + 1][prev][modulo])
            add(dp[i][last][(pw[j] * last + modulo) % m],
                dp[i + 1][prev][modulo]);
    }
  }
}
int solve(string &second) {
  int res = 0;
  for (int i = 0, j = len - 1, taken = 0; i < len; i++, j--) {
    for (int j = 0; j < second[i] - '0'; j++) {
      int last = (m - taken) % m;
      if (last < 0) last += m;
      add(res, dp[i][j][last]);
    }
    if ((i % 2 == 1 && second[i] - '0' != dig) ||
        (i % 2 == 0 && second[i] - '0' == dig))
      break;
    taken = (taken + pw[j] * (second[i] - '0')) % m;
    if (i == len - 1 && taken == 0) add(res, 1);
  }
  return res;
}
bool is_ok(string &second) {
  int now = 0;
  for (int i = 0; i < len; i++) {
    now = now * 10 + second[i] - '0';
    now %= m;
    if (i % 2 == 1 && second[i] - '0' != dig) return 0;
    if (i % 2 == 0 && second[i] - '0' == dig) return 0;
  }
  return (now == 0);
}
string a, b;
int main() {
  cin >> m >> dig >> a >> b;
  len = int((a).size());
  init();
  int ans = solve(b) - solve(a);
  if (ans < 0) ans += mod;
  if (is_ok(a)) add(ans, 1);
  cout << ans;
  return 0;
}
