#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const int N = 2 * 1e5 + 10;
ll res, m, d;
;
ll a[N];
std::vector<ll> v;
ll dp[2005][2][2][2][2005];
ll go(ll idx, ll fl, ll offset, ll gg, ll rem) {
  if (idx == v.size()) return rem == 0;
  if (dp[idx][fl][offset][gg][rem] + 1) return dp[idx][fl][offset][gg][rem];
  ll ans = 0, lm;
  for (int i = 0 + offset; i <= 9; ++i) {
    if (gg == idx % 2) {
      if (fl) {
        if (i != d)
          ans = (ans + go(idx + 1, 1, 0, gg, (rem * 10 + i) % m)) % mod;
      } else {
        if (i < v[idx]) {
          if (i != d) {
            ans = (ans + go(idx + 1, 1, 0, gg, (rem * 10 + i) % m)) % mod;
          }
        } else if (i == v[idx] && i != d) {
          ans = (ans + go(idx + 1, 0, 0, gg, (rem * 10 + i) % m)) % mod;
        } else
          break;
      }
    } else {
      if (fl) {
        ans = (ans + go(idx + 1, 1, 0, gg, (rem * 10 + d) % m)) % mod;
        break;
      } else {
        if (d < v[idx]) {
          ans = (ans + go(idx + 1, 1, 0, gg, (rem * 10 + d) % m)) % mod;
          break;
        } else if (d == v[idx]) {
          ans = (ans + go(idx + 1, 0, 0, gg, (rem * 10 + d) % m)) % mod;
          break;
        } else
          break;
      }
    }
  }
  return dp[idx][fl][offset][gg][rem] = ans % mod;
}
ll get(string s) {
  v.clear();
  while (s.size()) {
    v.push_back(s.back() - '0');
    s.pop_back();
  }
  reverse(v.begin(), v.end());
  ll ans = 0;
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < v.size(); ++i) {
    ans += go(i, i > 0, 1, i % 2, 0);
  }
  return ans;
}
bool check(string s) {
  ll xx = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (i % 2) {
      if (s[i] - '0' != d) return false;
    } else {
      if (s[i] - '0' == d) return false;
    }
    xx = (xx * 10 + s[i] - '0') % m;
  }
  return xx == 0;
}
void solve() {
  cin >> m >> d;
  string s, ss;
  cin >> s >> ss;
  cout << (get(ss) - get(s) + check(s) + mod) % mod;
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  while (t--) {
    solve();
  }
}
