#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n, M, d, ff[2005][2][2005][2];
char A[2005], B[2005], num[2005];
void Load(char* a) {
  n = 0;
  for (int i = strlen(a) - 1; i >= 0; i--) {
    num[n++] = a[i];
  }
  num[n] = '\0';
}
int dfs(int pos, int chk, int rem, int mgc) {
  if (pos == n) return (mgc && !rem);
  int& ret = ff[pos][chk][rem][mgc];
  if (~ret) return ret;
  ret = 0;
  int now = n - pos - 1, lim = chk ? 10 : num[now] - '0', ok;
  for (int dgt = 0; dgt < lim; dgt++) {
    ok = ((now & 1 && dgt != d) || (now % 2 == 0 && dgt == d)) ? 0 : 1;
    ret = (ret % MOD + dfs(pos + 1, 1, (rem * 10 + dgt) % M, mgc & ok)) % MOD;
  }
  if (!chk) {
    ok = ((now & 1 && (num[now] - '0') != d) ||
          (now % 2 == 0 && (num[now] - '0') == d))
             ? 0
             : 1;
    ret = (ret % MOD +
           dfs(pos + 1, 0, (rem * 10 + num[now] - '0') % M, mgc & ok)) %
          MOD;
  }
  return ff[pos][chk][rem][mgc] = ret % MOD;
}
int dfs1(int pos, int chk, int rem, int mgc) {
  if (pos == n) return (mgc && !rem);
  int& ret = ff[pos][chk][rem][mgc];
  if (~ret) return ret;
  ret = 0;
  int now = n - pos - 1, lim = chk ? 10 : num[now] - '0', ok;
  for (int dgt = 0; dgt < lim; dgt++) {
    ok = ((now & 1 && dgt == d) || (now % 2 == 0 && dgt != d)) ? 0 : 1;
    ret = (ret % MOD + dfs1(pos + 1, 1, (rem * 10 + dgt) % M, mgc & ok)) % MOD;
  }
  if (!chk) {
    ok = ((now & 1 && (num[now] - '0') == d) ||
          (now % 2 == 0 && (num[now] - '0') != d))
             ? 0
             : 1;
    ret = (ret % MOD +
           dfs1(pos + 1, 0, (rem * 10 + num[now] - '0') % M, mgc & ok)) %
          MOD;
  }
  return ff[pos][chk][rem][mgc] = ret % MOD;
}
int main() {
  scanf("%d %d %s %s", &M, &d, A, B);
  int rem = 0, f = 1;
  n = strlen(A);
  for (int i = n - 1, j = 0; i >= 0; i--, j++) {
    if (n & 1) {
      if (j & 1)
        f &= (A[i] - '0' == d);
      else
        f &= (A[i] - '0' != d);
    } else {
      if (j & 1)
        f &= (A[i] - '0' != d);
      else
        f &= (A[i] - '0' == d);
    }
    rem = (rem * 10 + A[j] - '0') % M;
  }
  f &= (rem == 0);
  Load(A);
  memset(ff, -1, sizeof ff);
  int lo = n & 1 ? dfs(0, 0, 0, 1) : dfs1(0, 0, 0, 1);
  Load(B);
  memset(ff, -1, sizeof ff);
  int hi = n & 1 ? dfs(0, 0, 0, 1) : dfs1(0, 0, 0, 1);
  int res = (hi - lo + f + MOD) % MOD;
  printf("%d\n", res);
  return 0;
}
