#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
const int M = 1e5 + 5;
const int mod = 1e9 + 7;
const double pi = 2 * acos(0);
int m, d;
string s;
int dp[N][N][2];
int add(int a, int b) { return (a + b) % mod; }
int solve(int idx, int md, bool flag) {
  if (idx == (int)s.size()) return !md;
  int &ans = dp[idx][md][flag];
  if (~ans) return ans;
  ans = 0;
  if (idx & 1) {
    if (flag || d <= s[idx] - '0')
      ans = add(ans,
                solve(idx + 1, (md * 10 + d) % m, (d < s[idx] - '0' | flag)));
  } else {
    for (int i = 0; i <= 9; i++) {
      if (i == d || (!flag && i > s[idx] - '0')) continue;
      if (!i && !idx) continue;
      ans = add(ans,
                solve(idx + 1, (md * 10 + i) % m, (flag | i < s[idx] - '0')));
    }
  }
  return ans;
}
bool tmam(string ss) {
  int md = 0;
  for (int i = 0; i < (int)ss.size(); i++) {
    if (i % 2 && (ss[i] - '0') != d) return false;
    if (i % 2 == 0 && (ss[i] - '0') == d) return false;
    md = (md * 10 + (ss[i] - '0')) % m;
  }
  return !md;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> m >> d;
  string a, b;
  cin >> a >> b;
  memset(dp, -1, sizeof dp);
  s = b;
  int ans = solve(0, 0, 0);
  s = a;
  memset(dp, -1, sizeof dp);
  ans = ((ans - solve(0, 0, 0) + tmam(a)) % mod + mod) % mod;
  cout << ans;
  return 0;
}
