#include <bits/stdc++.h>
const int Inf = 2 * 1000 * 1000 * 1000;
long long LINF = (long long)4e18;
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int maxn = 2000 + 5;
int D[maxn][maxn][2];
int m, d;
int add(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
int sub(int a, int b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
void inc(int &a, int b) { a = add(a, b); }
void dec(int &a, int b) { a = sub(a, b); }
int solve(string &s) {
  int n = (int)s.size();
  memset(D, 0, sizeof(D));
  D[0][0][1] = 1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < 2; k++) {
        for (int l = 0; l <= (k ? int(s[i] - '0') : 9); l++) {
          if ((i & 1) && l != d) continue;
          if (!(i & 1) && l == d) continue;
          if (!i && !l) continue;
          int ni = i + 1;
          int nj = (j * 10 + l) % m;
          int nk = k && (l == (s[i] - '0'));
          inc(D[ni][nj][nk], D[i][j][k]);
        }
      }
    }
  }
  return add(D[n][0][0], D[n][0][1]);
}
bool good(string &s) {
  int rem = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    int l = s[i] - '0';
    if ((i & 1) && l != d) return false;
    if (!(i & 1) && l == d) return false;
    rem = (rem * 10 + l) % m;
  }
  return rem == 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> d;
  string a, b;
  cin >> a >> b;
  int ans = 0;
  inc(ans, solve(b));
  dec(ans, solve(a));
  inc(ans, good(a));
  cout << ans;
  return 0;
}
