#include <bits/stdc++.h>
using namespace std;
long long dp[2005][2005][2];
long long ve[2005];
long long m, d;
long long dfs(long long pos, long long sum, long long lead, long long op,
              long long flag) {
  if (pos == 0) {
    if (sum % m == 0)
      return 1;
    else
      return 0;
  }
  if ((!op) && (!lead) && (dp[pos][sum][flag] != -1)) {
    return dp[pos][sum][flag];
  }
  long long tmp = op ? ve[pos] : 9;
  long long ans = 0;
  for (long long i = 0; i <= tmp; i++) {
    if ((lead) && (i == 0))
      ans = (ans + dfs(pos - 1, 0, lead, op && i == tmp, 0) + 1000000007) %
            1000000007;
    else if ((lead)) {
      if (i != d)
        ans = (ans + dfs(pos - 1, i % m, 0, op && i == tmp, 0) + 1000000007) %
              1000000007;
    } else {
      if (flag) {
        if (i != d)
          ans = (ans +
                 dfs(pos - 1, (sum * 10 + i) % m, 0, op && i == tmp, flag ^ 1) +
                 1000000007) %
                1000000007;
      } else if (i == d)
        ans = (ans +
               dfs(pos - 1, (sum * 10 + i) % m, 0, op && i == tmp, flag ^ 1) +
               1000000007) %
              1000000007;
    }
    ans = (ans + 1000000007) % 1000000007;
  }
  if ((!lead) && (!op)) dp[pos][sum][flag] = (ans + 1000000007) % 1000000007;
  return (ans + 1000000007) % 1000000007;
}
long long solve(string nu) {
  long long len = 0;
  ve[len++] = -1;
  for (long long i = nu.size() - 1; i >= 0; i--) {
    ve[len++] = nu[i] - '0';
  }
  return (dfs(len - 1, 0, 1, 1, 0) + 1000000007) % 1000000007;
}
int main() {
  memset(dp, -1, sizeof(dp));
  string l, r;
  scanf("%lld%lld", &m, &d);
  cin >> l >> r;
  long long ans = (solve(r) + 1000000007) % 1000000007;
  long long ans2 = (solve(l) + 1000000007) % 1000000007;
  ans = (ans - ans2 + 1000000007) % 1000000007;
  long long tmp = 0;
  long long flag = 0;
  for (long long i = 0; i < l.size(); i++) {
    tmp *= 10;
    tmp += (l[i] - '0');
    tmp %= m;
    if (i % 2) {
      if ((l[i] - '0') != d) {
        flag++;
        break;
      }
    } else {
      if ((l[i] - '0') == d) {
        flag++;
        break;
      }
    }
  }
  if ((!tmp) && (!flag)) ans++;
  cout << ((ans + 1000000007) % 1000000007) << endl;
  return 0;
}
