#include <bits/stdc++.h>
using namespace std;
long long dp[2005][2005][2][2];
long long m, d;
string a, b;
long long solve(long long pos, long long remain, bool safeA, bool safeB) {
  if (pos == b.length()) {
    if (remain == 0) {
      return 1;
    }
    return 0;
  }
  if (dp[pos][remain][safeA][safeB] != -1) return dp[pos][remain][safeA][safeB];
  int low, up;
  if (safeA) {
    low = 0;
  } else {
    low = a[pos] - '0';
  }
  if (safeB) {
    up = 9;
  } else {
    up = b[pos] - '0';
  }
  long long ans = 0;
  for (int x = low; x <= up; x++) {
    if (pos % 2 == 0 && x == d) continue;
    if (pos % 2 == 1 && x != d) continue;
    ans +=
        solve(pos + 1, (remain * 10 + x) % m, safeA | x > low, safeB | x < up);
    ans %= 1000000007;
  }
  return dp[pos][remain][safeA][safeB] = ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> d >> a >> b;
  fill(dp[0][0][0], dp[b.length()][m][2], -1);
  cout << solve(0, 0, false, false) % 1000000007 << "\n";
  return 0;
}
