#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2001;
int m, d, len, a[N];
long long dp[N][N];
long long dfs(int pos, int sta, bool limit) {
  if (pos == -1) return sta == 0;
  if (!limit && dp[pos][sta] != -1) return dp[pos][sta];
  int up = (limit ? a[pos] : 9);
  long long res = 0;
  for (int i = 0; i <= up; i++) {
    if (((len - pos) % 2 == 0 && i != d) || ((len - pos) % 2 == 1 && i == d))
      continue;
    res += dfs(pos - 1, (sta * 10 + i) % m, limit && i == a[pos]) % mod;
  }
  if (!limit) dp[pos][sta] = res;
  return res;
}
long long solve(string s) {
  len = s.size();
  for (int i = 0; i < len; i++) {
    a[i] = s[len - i - 1] - '0';
  }
  return dfs(len - 1, 0, true);
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> m >> d;
  string l, r;
  cin >> l >> r;
  long long flag = 1, num = 0;
  for (int i = 0; i < l.size() && flag; i++) {
    num = (num * 10 + l[i] - '0') % m;
    if (((i + 1) % 2 == 0 && l[i] - '0' != d) ||
        ((i + 1) % 2 == 1 && l[i] - '0' == d)) {
      flag = 0;
    }
  }
  if (flag) {
    flag = (num ? 0 : 1);
  }
  cout << (solve(r) - solve(l) + flag) % mod << endl;
  return 0;
}
