#include <bits/stdc++.h>
using namespace std;
int m, k, n;
const int mod = 1e9 + 7;
char aa[2005], bb[2005];
int a[2005], b[2005];
long long d[2005][2005][2];
long long dfs(int pos, int sta, int limit, int x[]) {
  if (pos == n + 1) return (sta == 0);
  if (d[pos][sta][limit] != -1) return d[pos][sta][limit];
  int up = limit ? x[pos] : 9;
  long long ans = 0;
  for (int i = 0; i <= up; i++) {
    if (pos % 2 == 0 && i != k) continue;
    if (pos % 2 && i == k) continue;
    int sta2 = (sta * 10 + i) % m;
    ans = (ans + dfs(pos + 1, sta2, limit && i == up, x)) % mod;
  }
  return d[pos][sta][limit] = ans;
}
bool ok() {
  int i, tmp = 0;
  for (i = 1; i <= n; i++) {
    if (i % 2 && a[i] == k) break;
    if (i % 2 == 0 && a[i] != k) break;
    tmp = (tmp * 10 + a[i]) % m;
  }
  return tmp % m == 0 && i == n + 1;
}
int main() {
  scanf("%d%d", &m, &k);
  scanf("%s%s", aa + 1, bb + 1);
  n = strlen(aa + 1);
  for (int i = 1; i <= n; i++) {
    a[i] = aa[i] - '0';
    b[i] = bb[i] - '0';
  }
  memset(d, -1, sizeof(d));
  long long ans = dfs(1, 0, 1, b);
  memset(d, -1, sizeof(d));
  ans = (ans - dfs(1, 0, 1, a) + mod) % mod;
  if (ok()) ++ans;
  printf("%lld\n", ans);
  return 0;
}
