#include <bits/stdc++.h>
using namespace std;
const long Mod = 1e9 + 7;
long M, d, len, f[2005][2005][2][2];
string a, b;
long dq(long x, long du, bool ok1, bool ok2) {
  if (x > len) return (du == 0);
  if (f[x][du][ok1][ok2] != -1) return f[x][du][ok1][ok2];
  long rs = 0, l, r;
  if (x % 2 == 0) {
    l = 0;
    r = 9;
    if (!ok1) l = a[x] - '0';
    if (!ok2) r = b[x] - '0';
    if (l <= d && d <= r)
      rs = (rs + dq(x + 1, (du * 10 + d) % M, ok1 | (d != l), ok2 | (d != r))) %
           Mod;
  } else {
    l = 0;
    r = 9;
    if (!ok1) l = a[x] - '0';
    if (!ok2) r = b[x] - '0';
    for (long i = l; i <= r; i++)
      if (i != d)
        rs = (rs +
              dq(x + 1, (du * 10 + i) % M, ok1 | (i != l), ok2 | (i != r))) %
             Mod;
  }
  return f[x][du][ok1][ok2] = rs;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> M >> d >> a >> b;
  memset(f, -1, sizeof f);
  len = a.size();
  a = '0' + a;
  b = '0' + b;
  cout << dq(1, 0, 0, 0) << '\n';
}
