#include <bits/stdc++.h>
using namespace std;
int dp[2005][2005][2][2];
int m, d, mod = 1e9 + 7;
string a, b;
int solve(int i, int mm, bool aa, bool bb) {
  if (i == a.size()) return !mm;
  int &x = dp[i][mm][aa][bb];
  if (x != -1) return x;
  x = 0;
  for (int j = 0; j <= 9; j++) {
    if (i % 2 && j != d || !(i % 2) && j == d) continue;
    if (!aa && a[i] - '0' > j || !bb && b[i] - '0' < j) continue;
    bool na = aa | a[i] - '0' < j, nb = bb | b[i] - '0' > j;
    x = (x + solve(i + 1, (mm * 10 + j) % m, na, nb)) % mod;
  }
  return x;
}
int main() {
  cin >> m >> d >> a >> b;
  memset(dp, -1, sizeof dp);
  cout << solve(0, 0, 0, 0);
}
