#include <bits/stdc++.h>
using namespace std;
int dis[2005], cnt, m, d, MOD = (1e9 + 7);
long long dp[2005][2005];
char a[2005], b[2005];
long long dfs(int n, int odd, int ss, int doing) {
  if (n == 0 && ss == 0) {
    return 1;
  }
  if (n == 0) return 0;
  if (dp[n][ss] != -1 && !doing) {
    return dp[n][ss];
  }
  int ent = doing == 0 ? 9 : dis[n];
  long long ans = 0;
  if (!odd) {
    if (d <= ent) ans = dfs(n - 1, !odd, (ss * 10 + d) % m, ent == d && doing);
  } else {
    for (int i = 0; i <= ent; i++) {
      if (i == d)
        continue;
      else
        ans = (ans + dfs(n - 1, !odd, (ss * 10 + i) % m, i == ent && doing) +
               MOD) %
              MOD;
    }
  }
  if (!doing) dp[n][ss] = ans;
  return ans;
}
long long solve(char *x) {
  memset(dp, -1, sizeof(dp));
  int len = strlen(x);
  cnt = 0;
  for (int i = len - 1; i >= 0; i--) {
    dis[++cnt] = (long long)(x[i] - '0');
  }
  return dfs(cnt, 1, 0, 1);
}
int main() {
  scanf("%d%d", &m, &d);
  scanf("%s", a);
  scanf("%s", b);
  long long t = 1;
  int len = strlen(a), tmp = 0;
  for (int i = 0; i < len; i++) {
    int ch = a[i] - '0';
    if (i & 1) {
      if (ch != d) {
        t = 0;
        break;
      }
    } else if (ch == d) {
      t = 0;
      break;
    }
    tmp = (tmp * 10 + ch) % m;
  }
  if (tmp != 0) t = 0;
  printf("%I64d\n", (solve(b) - solve(a) + t + MOD) % MOD);
}
