#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int m, d;
string s;
int dp[2005][2005][2];
void add(int& ret, int y) {
  ret %= mod;
  y %= mod;
  ret += y;
  ret %= mod;
}
int go(int ind, int rem, bool less) {
  if (ind == s.size()) {
    if (rem == 0) return 1;
    return 0;
  }
  if (dp[ind][rem][less] != -1) return dp[ind][rem][less];
  int ret = 0;
  int cur = s[ind] - '0';
  if (ind % 2) {
    if (less || cur > d)
      add(ret, go(ind + 1, (rem * 10 + d) % m, 1));
    else if (cur == d)
      add(ret, go(ind + 1, (rem * 10 + d) % m, less));
  } else {
    for (int i = 0; i <= 9; i++) {
      if (i == d || (ind == 0 && i == 0)) continue;
      if (i < cur || less)
        add(ret, go(ind + 1, (rem * 10 + i) % m, 1));
      else if (i == cur)
        add(ret, go(ind + 1, (rem * 10 + i) % m, less));
    }
  }
  return dp[ind][rem][less] = ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string a, b;
  cin >> m >> d >> a >> b;
  memset(dp, -1, sizeof dp);
  s = b;
  int mx = go(0, 0, 0);
  s = a;
  memset(dp, -1, sizeof dp);
  int mi = go(0, 0, 0);
  mx = ((mx - mi) % mod + mod) % mod;
  int tmp = 0;
  bool f = true;
  for (int i = 0; i < a.length(); i++) {
    int cur = a[i] - '0';
    if ((i % 2 && cur != d) || (i % 2 == 0 && cur == d)) {
      f = false;
      break;
    }
    tmp *= 10;
    tmp += (a[i] - '0');
    tmp %= m;
  }
  if (f && !tmp) mx++;
  mx %= mod;
  cout << mx << "\n";
  return 0;
}
