#include <bits/stdc++.h>
using namespace std;
const int mx = 2123;
const long long mod = 1e9 + 7;
long long dp[mx][mx];
long long p[mx];
string upper;
int m, d;
int sz;
long long solve(int on, long long x, bool f) {
  if (on > sz) {
    if (x == 0) return 1;
    return 0;
  }
  if (f) {
    if (dp[on][x] != -1) return dp[on][x];
    dp[on][x] = 0;
  }
  long long ans = 0, y;
  for (int i = (on == 1); i < 10; i++) {
    if (on % 2 == 0 && i != d) continue;
    if (on % 2 != 0 && i == d) continue;
    if (!f && i > upper[on - 1]) continue;
    y = (x + i * p[sz - on + 1]) % m;
    if (f) {
      dp[on][x] += solve(on + 1, y, f);
    } else {
      ans += solve(on + 1, y, i < upper[on - 1]);
    }
  }
  if (f) {
    dp[on][x] %= mod;
    ans = dp[on][x];
  }
  return ans % mod;
}
int main() {
  cin >> m >> d;
  string a, b;
  cin >> a;
  cin >> b;
  p[1] = 1 % m;
  for (int i = 2; i <= a.size(); i++) {
    p[i] = (p[i - 1] * 10) % m;
  }
  for (int i = 0; i < a.size(); i++) {
    a[i] -= '0';
    b[i] -= '0';
  }
  memset(dp, -1, sizeof dp);
  upper = a;
  sz = a.size();
  long long ansa = solve(1, 0, 0);
  bool magic = true;
  long long x = 0;
  for (int i = 1; i <= a.size(); i++) {
    if (i % 2 == 0) {
      magic &= (a[i - 1] == d);
    } else {
      magic &= (a[i - 1] != d);
    }
    x = (x + (a[i - 1]) * p[sz - i + 1]) % m;
  }
  if (magic && x == 0) ansa--;
  upper = b;
  sz = b.size();
  long long ansb = solve(1, 0, 0);
  cout << ((ansb - ansa + mod) % mod) << endl;
}
