#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
const int N = 2e3 + 100;
int dp[N][N];
char s[N];
int m, d;
int dfs(int len, int yu, int lim, int g) {
  if (!lim && dp[yu][len] != -1) return dp[yu][len];
  if (len == 0) {
    return !yu;
  }
  int up = 9;
  if (lim) up = s[len] - '0';
  long long tmp = 0;
  for (int i = 0; i <= up; ++i) {
    if (g) {
      if (i != d) continue;
    } else {
      if (i == d) continue;
    }
    tmp += dfs(len - 1, (yu * 10 + i) % m, lim && (i == up), g ^ 1);
  }
  tmp %= mod;
  if (!lim) dp[yu][len] = tmp;
  return tmp;
}
bool check(int len) {
  int yu = 0, g = 0;
  for (int i = len; i >= 1; --i) {
    if (g && s[i] != '0' + d) return false;
    if (!g && s[i] == '0' + d) return false;
    yu = (yu * 10 + s[i] - '0') % m;
    g ^= 1;
  }
  return yu == 0;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%d%d", &m, &d);
  scanf("%s", s + 1);
  int len1 = strlen(s + 1);
  reverse(s + 1, s + 1 + len1);
  long long ans = check(len1) - dfs(len1, 0, 1, 0);
  scanf("%s", s + 1);
  len1 = strlen(s + 1);
  reverse(s + 1, s + 1 + len1);
  ans += mod + dfs(len1, 0, 1, 0);
  ans %= mod;
  cout << ans << endl;
  return 0;
}
