#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int msz = 10000;
const double eps = 1e-8;
char a[2333], b[2333];
long long dp[2333][2333][3];
int m, d, len;
long long dfs(int high, int pos, int md) {
  if (pos == len) return md == 0;
  if (~dp[pos][md][high % 3]) return dp[pos][md][high % 3];
  long long ans = 0;
  int st, en;
  st = (high != 2 && high != 1) ? a[pos] - '0' : 0;
  en = (high != 2 && high != 0) ? b[pos] - '0' : 9;
  int nhigh;
  if (pos & 1) {
    for (int i = st; i <= en; ++i) {
      if (i == d) continue;
      if (high == 3 && st == en)
        nhigh = 3;
      else if ((high == 0 || high == 3) && i == st)
        nhigh = 0;
      else if ((high == 1 || high == 3) && i == en)
        nhigh = 1;
      else
        nhigh = 2;
      ans = (ans + dfs(nhigh, pos + 1, (md * 10 + i) % m)) % mod;
    }
  } else if (st <= d && d <= en) {
    if (high == 3 && st == en)
      nhigh = 3;
    else if ((high == 0 || high == 3) && st == d)
      nhigh = 0;
    else if ((high == 1 || high == 3) && en == d)
      nhigh = 1;
    else
      nhigh = 2;
    ans = (ans + dfs(nhigh, pos + 1, (md * 10 + d) % m)) % mod;
  }
  dp[pos][md][high % 3] = ans;
  return ans;
}
int main() {
  scanf("%d%d%s%s", &m, &d, a + 1, b + 1);
  memset(dp, -1, sizeof(dp));
  len = strlen(a + 1) + 1;
  printf("%lld\n", dfs(3, 1, 0));
  return 0;
}
