#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];
string num;
int dfs(int pos, int chk, int rem, int mgc) {
  if (pos == n) return (!rem && mgc);
  int& ret = ff[pos][chk][rem][mgc];
  if (~ret) return ret;
  ret = 0;
  int lim = chk ? 10 : num[pos] - '0', ok;
  for (int dgt = 0; dgt < lim; dgt++) {
    ok = pos & 1 ? (dgt == D) : (dgt != D);
    ret = (ret % MOD + dfs(pos + 1, 1, (rem * 10 + dgt) % M, mgc & ok) % MOD) %
          MOD;
  }
  if (!chk) {
    ok = pos & 1 ? (num[pos] - '0' == D) : (num[pos] - '0' != D);
    ret = (ret % MOD +
           dfs(pos + 1, 0, (rem * 10 + num[pos] - '0') % M, mgc & ok) % MOD) %
          MOD;
  }
  return ff[pos][chk][rem][mgc] = ret % MOD;
}
int main() {
  scanf("%d %d %s %s", &M, &D, &A, &B);
  n = strlen(A);
  int f = 1, rem = 0;
  for (int i = 0; i < n; i++) {
    f &= (i & 1 ? (A[i] - '0' == D) : (A[i] - '0' != D));
    rem = (rem * 10 + A[i] - '0') % M;
  }
  f &= (rem == 0);
  num = A;
  memset(ff, -1, sizeof ff);
  int lo = dfs(0, 0, 0, 1);
  num = B, n = strlen(B);
  memset(ff, -1, sizeof ff);
  int hi = dfs(0, 0, 0, 1);
  int res = (hi - lo + f + MOD) % MOD;
  printf("%d\n", res);
  return 0;
}
