#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, modd = 1e9 + 7, inf = 2e9;
const double pi = 3.14159265359;
long long fp(long long base, long long exp, long long mod) {
  if (exp == 0) return 1;
  long long ans = fp(base, exp / 2, mod);
  ans = (ans * ans) % mod;
  if (exp % 2 != 0) ans = (ans * (base % mod)) % mod;
  return ans;
}
long long phi(long long n) {
  long long p_to_k, ret = 1;
  for (long long i = 2, d = 1; i * i <= n; i += d, d = 2) {
    if (n % i == 0) {
      p_to_k = 1;
      while (n % i == 0) {
        p_to_k *= i;
        n /= i;
      }
      ret *= (p_to_k / i) * (i - 1);
    }
  }
  if (n != 1) ret *= (n - 1);
  return ret;
}
long long div(long long n) {
  long long cnt = 0;
  for (long long i = 1LL; i <= sqrt(n); ++i) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt += 2;
    }
  }
  return cnt;
}
int m, d;
string a, b;
long long dp[2005][2005][2][2];
long long fun(int indx, int num, int f1, int f2) {
  if (indx == a.length()) {
    return (num == 0);
  }
  long long &ret = dp[indx][num][f1][f2];
  if (~ret) return ret;
  long long res = 0LL;
  for (int i = '0'; i <= '9'; ++i) {
    if (!f1 && i < a[indx]) continue;
    if (!f2 && i > b[indx]) continue;
    if ((indx % 2) ^ ((i - '0') == d)) continue;
    res = (res + fun(indx + 1, ((num * 10) + (i - '0')) % m, f1 || i > a[indx],
                     f2 || i < b[indx])) %
          modd;
  }
  return ret = res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> d >> a >> b;
  memset(dp, -1, sizeof(dp));
  long long ans = fun(0, 0, 0, 0);
  cout << ans;
  return 0;
}
