#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}
template <class T>
auto dud(T *x) -> decltype(cerr << *x, 0);
template <class T>
char dud(...);
struct debug {
  template <class T>
  debug &operator<<(const T &) {
    return *this;
  }
};
const int N = 2005, mod = 1e9 + 7;
int m, d, timer = 0, mem[N][N][2][2], done[N][N][2][2];
string l, r;
int dp(int i, int sum, bool small, bool big) {
  if (i == (int)r.size()) return sum % m == 0;
  int &ans = mem[i][sum][small][big];
  if (done[i][sum][small][big] != timer) {
    done[i][sum][small][big] = timer;
    ans = 0;
    int lo = small ? 0 : l[i] - '0';
    int hi = big ? 9 : r[i] - '0';
    for (auto d = (lo) - ((lo) > (hi + 1)); d != hi + 1 - ((lo) > (hi + 1));
         d += 1 - 2 * ((lo) > (hi + 1))) {
      bool inv = (i & 1) && d == ::d;
      inv |= !(i & 1) && d != ::d;
      if (inv) continue;
      (ans +=
       dp(i + 1, (sum * 10 + d) % m, small | (d > lo), big | (d < hi))) %= mod;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  while (cin >> m >> d >> l >> r) {
    ++timer;
    l = "$" + l, r = "$" + r;
    memset(mem, 0, sizeof mem);
    cout << dp(1, 0, 0, 0) << '\n';
    debug();
  }
  return 0;
}
