#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
long long M10[10000];
long long dp[2500][2500][3];
int m, d;
string s1, s2;
int n;
long long mulmod(long long a, long long b, long long c) {
  long long x = 0, y = a % c;
  while (b > 0) {
    if (b % 2 == 1) x = (x + y) % c;
    y = (y * 2) % c;
    b /= 2;
  }
  return x % c;
}
long long modAdd(long long a, long long b, long long mod) {
  return ((a % mod) + (b % mod)) % mod;
}
long long sol(int i, int s, int flag) {
  long long &ret = dp[i][s][flag];
  if (i >= n) {
    return ret = (s == 0);
  }
  if (ret == -1) {
    ret = 0;
    int lo = !(flag & 1) ? (s1[i] - '0') : 0;
    int hi = !(flag & 2) ? (s2[i] - '0') : 9;
    if (i % 2 == 1) {
      int nflag = flag;
      if (d > (s1[i] - '0')) nflag |= 1;
      if (d < (s2[i] - '0')) nflag |= 2;
      if (d >= lo && d <= hi) {
        long long sp = mulmod(M10[n - i - 1], d, m);
        sp = modAdd(sp, s, m);
        ret += sol(i + 1, sp, nflag);
        ret %= (1000000000 + 7);
      }
    } else {
      for (int j = lo; j <= hi; ++j) {
        if (j == d) continue;
        long long sp = mulmod(M10[n - i - 1], j, m);
        sp = modAdd(sp, s, m);
        int nflag = flag;
        if (j > (s1[i] - '0')) nflag |= 1;
        if (j < (s2[i] - '0')) nflag |= 2;
        ret += sol(i + 1, sp, nflag);
        ret %= (1000000000 + 7);
      }
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> m >> d;
  cin >> s1 >> s2;
  n = s2.size();
  string zero;
  for (int i = 0; i < s2.size() - s1.size(); ++i) {
    zero.push_back('0');
  }
  s1 = zero + s1;
  memset((M10), (0), sizeof(M10));
  M10[0] = 1;
  for (int i = 1; i < 4000; ++i) {
    M10[i] = 10 * M10[i - 1];
    M10[i] %= m;
  }
  memset((dp), (-1), sizeof(dp));
  long long ans = sol(0, 0, 0);
  cout << ans << endl;
  return 0;
}
