#include <bits/stdc++.h>
using namespace std;
const long long M = 2001;
const long long N = 2001;
const long long D = 10;
long long dp[N][M][2];
vector<long long> v;
long long m, d, n;
long long mod = 1e9 + 7;
long long add(long long a, long long b) {
  return ((a % mod) + (b % mod)) % mod;
}
long long sub(long long a, long long b) {
  return ((a % mod) - (b % mod) + mod) % mod;
}
long long solve(long long idx, long long rem, long long flag) {
  if (idx == n) {
    return (rem == 0);
  }
  if (dp[idx][rem][flag] != -1) return dp[idx][rem][flag];
  long long ans = 0;
  if (idx % 2 == 0) {
    long long up;
    if (flag == 0) {
      up = v[idx];
    } else {
      up = 9;
    }
    for (long long i = 0; i <= up; i++) {
      if (i == d) continue;
      if (idx == 0 && i == 0) continue;
      if (i < v[idx]) {
        ans = add(ans, solve(idx + 1, (rem * 10 + i) % m, 1));
      } else {
        ans = add(ans, solve(idx + 1, (rem * 10 + i) % m, flag));
      }
    }
  } else {
    if (flag == 0) {
      if (d < v[idx])
        ans = solve(idx + 1, (rem * 10 + d) % m, 1);
      else if (d == v[idx])
        ans = solve(idx + 1, (rem * 10 + d) % m, 0);
    } else {
      ans = solve(idx + 1, (rem * 10 + d) % m, flag);
    }
  }
  dp[idx][rem][flag] = ans;
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> m >> d;
  string aa, bb;
  cin >> aa;
  cin >> bb;
  for (auto i : bb) {
    v.push_back(i - '0');
  }
  n = (long long)v.size();
  memset(dp, -1, sizeof(dp));
  long long r = solve(0, 0, 0);
  memset(dp, -1, sizeof(dp));
  v.clear();
  for (auto i : aa) {
    v.push_back(i - '0');
  }
  n = v.size();
  if (v[n - 1] == 0) {
    v[n - 1] = 9;
    long long idx = n - 2;
    while (idx >= 0 && v[idx] == 0) {
      v[idx] = 9;
      idx--;
    }
    v[idx]--;
  } else
    v[n - 1]--;
  long long l = solve(0, 0, 0);
  long long ans = sub(r, l);
  cout << ans;
}
