#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int M, ALen, BLen;
char D, A[2010], B[2010];
long long ans = 0, F[2010][2010];
long long dfs(char* arr, int pos, long long sum, bool islim) {
  if (arr[pos] < '0' || arr[pos] > '9') return sum == 0;
  if (!islim && F[pos][sum] != -1) return F[pos][sum];
  int lim = islim ? (arr[pos] - '0') : 9;
  long long ret = 0, nsum = 0;
  for (int i = 0; i <= lim; ++i) {
    nsum = (sum * 10 + i) % M;
    if (pos % 2 == 1 && i == D - '0') continue;
    if (pos % 2 == 0 && i != D - '0') continue;
    ret = (ret + dfs(arr, pos + 1, nsum, islim && i == lim)) % mod;
  }
  if (!islim) F[pos][sum] = ret;
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(F, -1, sizeof(F));
  cin >> M >> D;
  cin >> A + 1;
  cin >> B + 1;
  ALen = strlen(A + 1);
  BLen = strlen(B + 1);
  int isAMagic = 1;
  long long sum = 0;
  for (int i = 1; i <= ALen; ++i) {
    sum = (sum * 10 + A[i] - '0') % M;
    if (i % 2 == 1 && A[i] == D) {
      isAMagic = 0;
      break;
    } else if (i % 2 == 0 && A[i] != D) {
      isAMagic = 0;
      break;
    }
  }
  if (sum) isAMagic = 0;
  ans = (dfs(B, 1, 0, 1) + mod - dfs(A, 1, 0, 1) + isAMagic) % mod;
  printf("%lld\n", ans);
  return 0;
}
