#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long dp[2005][2005], m, d, ans, bit[2005], len;
char l[2005], r[2005];
long long dfs(int pos, long long sum, bool flag) {
  if (pos == -1) return sum == 0;
  if (!flag && dp[pos][sum] != -1) return dp[pos][sum];
  long long res = 0;
  for (int i = 0, up = flag ? bit[pos] : 9; i <= up; ++i) {
    if ((len - pos) & 1) {
      if (i == d) continue;
    } else {
      if (i != d) continue;
    }
    (res += dfs(pos - 1, (sum * 10 + i) % m, flag && (i == up))) %= MOD;
  }
  return flag ? res : dp[pos][sum] = res;
}
long long calc(char *x) {
  len = strlen(x);
  for (int i = 0; i < len; ++i) bit[len - i - 1] = x[i] - '0';
  return dfs(len - 1, 0, 1);
}
int check() {
  long long sum = 0;
  len = strlen(l);
  for (int i = 0; i < len; ++i) {
    int x = l[i] - '0';
    if ((i + 1) & 1) {
      if (x == d) return 0;
    } else {
      if (x != d) return 0;
    }
    (sum = sum * 10 + x) %= m;
  }
  return sum == 0;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%lld%lld", &m, &d);
  scanf("%s", l);
  scanf("%s", r);
  ans = calc(r) - calc(l);
  ans += check();
  printf("%lld\n", (ans + MOD) % MOD);
  return 0;
}
