#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
const long double PI = 3.14159265358979;
long long binpow(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool parity(long long x, long long y) {
  bool f = ((x ^ y) < 0);
  return !f;
}
string getBase(long long x, long long b) {
  string ans;
  while (x) {
    ans += ('0' + x % b);
    x /= b;
  }
  return ans;
}
long long m, d;
string L, R;
long long dp[2002][2][2][2002];
long long cal(long long level, long long tlo, long long thi, long long rem) {
  if (level >= R.size()) {
    if (rem == 0) return 1;
    return 0;
  }
  long long &ret = dp[level][tlo][thi][rem];
  if (ret != -1) return ret;
  ret = 0;
  long long diglo = 0;
  long long dighi = 9;
  if (tlo) diglo = L[level] - '0';
  if (thi) dighi = R[level] - '0';
  if (dighi < diglo) return ret;
  if (level & 1) {
    if (d < diglo or d > dighi) return ret;
    long long newlo = tlo;
    long long newhi = thi;
    if (d > L[level] - '0') newlo = 0;
    if (d < R[level] - '0') newhi = 0;
    ret += cal(level + 1, newlo, newhi, (rem * 10 + d) % m);
    ret %= mod;
  } else {
    for (int i = diglo; i <= dighi; i++) {
      if (i == d) continue;
      long long newlo = tlo;
      long long newhi = thi;
      if (i > L[level] - '0') newlo = 0;
      if (i < R[level] - '0') newhi = 0;
      ret += cal(level + 1, newlo, newhi, (rem * 10 + i) % m);
      ret %= mod;
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> m >> d;
  cin >> L >> R;
  for (long long i = 0; i <= (2000); i++)
    for (long long j = 0; j <= (1); j++)
      for (long long k = 0; k <= (1); k++)
        for (long long kk = 0; kk <= (2000); kk++) dp[i][j][k][kk] = -1;
  cout << cal(0, 1, 1, 0) << '\n';
  return 0;
}
