#include <bits/stdc++.h>
using namespace std;
long long n, m, d, dp[2][2001][2001], g[2001], h[2001];
const long long mod = 1000 * 1000 * 1000 + 7;
string u, v;
long long go(long long a[]) {
  for (int i = 0; i < 2; i++)
    for (int j = 0; j <= n; j++)
      for (int k = 0; k < m; k++) dp[i][j][k] = 0;
  dp[1][0][0] = 1;
  for (int i = 0; i < n; i++)
    for (int k = 0; k < 2; k++)
      for (int h = 0; h < m; h++) {
        int r;
        if (k || !i)
          r = a[i];
        else
          r = 9;
        for (int j = 0; j <= r; j++) {
          if (!dp[k][i][h]) continue;
          if ((i % 2) && j != d) continue;
          if (!(i % 2) && j == d) continue;
          int ni = i + 1;
          int nh = (h * 10 + j) % m;
          int nk = k && j == a[i];
          dp[nk][ni][nh] += dp[k][i][h];
          dp[nk][ni][nh] %= mod;
        }
      }
  return (dp[0][n][0] + dp[1][n][0]) % mod;
}
bool good(long long a[]) {
  long long qwer = 0;
  for (int i = 0; i < n; i++) qwer += a[i], qwer %= m, qwer *= 10;
  bool is = !qwer;
  for (int i = 1; i < n; i += 2)
    if (a[i] != d) is = false;
  for (int i = 0; i < n; i += 2)
    if (a[i] == d) is = false;
  return is;
}
int main() {
  scanf("%d %d", &m, &d);
  cin >> u >> v;
  n = u.size();
  for (int i = 0; i < u.size(); i++) g[i] = u[i] - '0', h[i] = v[i] - '0';
  printf("%d\n", (go(h) + mod - go(g) + good(g)) % mod);
}
