#include <bits/stdc++.h>
using namespace std;
inline void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); }
inline long long Set(long long n, long long pos) { return n = n | (1 << pos); }
inline long long Reset(long long n, long long pos) {
  return n = n & ~(1 << pos);
}
inline bool Check(long long n, long long pos) { return (bool)(n & (1 << pos)); }
inline long long Count(long long n) { return __builtin_popcountll(n); }
long long const N = 2e3 + 10;
long long const MOD = 1e9 + 7;
long long m, d;
vector<long long> ar, br;
long long dp[N][N][2][2];
long long fun(long long rem, long long pos, bool s1, bool s2) {
  if (pos == (long long)ar.size()) {
    if (!rem) return 1;
    return 0;
  }
  long long &res = dp[rem][pos][s1][s2];
  if (res != -1) return res;
  long long left = s1 ? ar[pos] : 0;
  long long right = s2 ? br[pos] : 9;
  res = 0;
  for (long long i = left; i <= right; i++) {
    if (pos & 1 && i != d) continue;
    if (pos % 2 == 0 && i == d) continue;
    res += fun((rem * 10 + i) % m, pos + 1, s1 && ar[pos] == i,
               s2 && br[pos] == i);
    if (res > MOD) res -= MOD;
  }
  return res;
}
int32_t main() {
  fast();
  cin >> m >> d;
  string a, b;
  cin >> a >> b;
  memset(dp, -1, sizeof(dp));
  for (auto c : a) ar.push_back(c - '0');
  for (auto c : b) br.push_back(c - '0');
  cout << fun(0, 0, 1, 1) << '\n';
}
