#include <bits/stdc++.h>
using namespace std;
const int base = 1e9 + 7;
int Pow[2069], m, f[2069][2][2][2001], n;
string a, b;
char d;
int findre(int l, int a) { return (Pow[l] * a) % m; }
int cal(int i, int oka, int okb, int re) {
  if (f[i][oka][okb][re] != -1) return f[i][oka][okb][re];
  if (i == n + 1) {
    if (re == 0)
      return 1;
    else
      return 0;
  }
  int sum = 0;
  for (char k = '0'; k <= '9'; k++) {
    if ((oka || k >= a[i - 1]) && (okb || k <= b[i - 1])) {
      if (i % 2 == 0) {
        if (k == d) {
          sum += cal(i + 1, oka || k > a[i - 1], okb || k < b[i - 1],
                     (findre(n - i, int(k - 48)) + re) % m);
          sum %= base;
        }
      } else {
        if (k != d) {
          sum += cal(i + 1, oka || k > a[i - 1], okb || k < b[i - 1],
                     (findre(n - i, int(k - 48)) + re) % m);
          sum %= base;
        }
      }
    }
  }
  return f[i][oka][okb][re] = sum;
}
int main() {
  scanf("%d", &m);
  cin >> d;
  cin >> a;
  cin >> b;
  n = a.length();
  Pow[0] = 1;
  for (int i = 1; i <= n + 3; i++) {
    Pow[i] = (Pow[i - 1] * (10 % m)) % m;
  }
  memset(f, -1, sizeof(f));
  cout << cal(1, 0, 0, 0) << endl;
}
