#include <bits/stdc++.h>
const int p = 1000000007;
int main() {
  std::cout.sync_with_stdio(false);
  int m, d;
  std::string a, b;
  std::cin >> m >> d;
  std::cin >> a;
  std::cin >> b;
  int len = a.length();
  short currentIndex = 0;
  std::vector<long long> resultsBetween[2];
  bool areABequal = true;
  int equalA = 1, equalB = 1;
  int remainderA = 0, remainderB = 0;
  for (int i = 0; i < 2; i++) {
    resultsBetween[i] = std::vector<long long>(m, 0);
  }
  for (int i = 0; i < len; i++) {
    for (int j = 0; j < m; j++) resultsBetween[1 - currentIndex][j] = 0;
    if (i % 2 == 0) {
      for (int j = 0; j < 10; j++) {
        if (j == d) continue;
        for (int r = 0; r < m; r++) {
          resultsBetween[1 - currentIndex][(10 * r + j) % m] +=
              resultsBetween[currentIndex][r];
        }
      }
      remainderA = (remainderA * 10) % m;
      remainderB = (remainderB * 10) % m;
      if (areABequal) {
        for (int j = 1 + (a[i] - '0'); j < (b[i] - '0'); j++) {
          if (j == d) continue;
          resultsBetween[1 - currentIndex][(remainderA + j) % m] += equalA;
        }
        if (a[i] != b[i]) areABequal = false;
      } else {
        for (int j = 1 + (a[i] - '0'); j < 10; j++) {
          if (j == d) continue;
          resultsBetween[1 - currentIndex][(remainderA + j) % m] += equalA;
        }
        for (int j = 0; j < (b[i] - '0'); j++) {
          if (j == d) continue;
          resultsBetween[1 - currentIndex][(remainderB + j) % m] += equalB;
        }
      }
      remainderA = (remainderA + (a[i] - '0')) % m;
      remainderB = (remainderB + (b[i] - '0')) % m;
      if ((a[i] - '0') == d) equalA = 0;
      if ((b[i] - '0') == d) equalB = 0;
      currentIndex = 1 - currentIndex;
    } else {
      for (int r = 0; r < m; r++) {
        resultsBetween[1 - currentIndex][(10 * r + d) % m] +=
            resultsBetween[currentIndex][r];
      }
      remainderA = (remainderA * 10) % m;
      remainderB = (remainderB * 10) % m;
      if (areABequal) {
        if ((d > (a[i] - '0')) && (d < (b[i] - '0')))
          resultsBetween[1 - currentIndex][(remainderA + d) % m] += equalA;
        if (a[i] != b[i]) areABequal = false;
      } else {
        if (d > (a[i] - '0'))
          resultsBetween[1 - currentIndex][(remainderA + d) % m] += equalA;
        if (d < (b[i] - '0'))
          resultsBetween[1 - currentIndex][(remainderB + d) % m] += equalB;
      }
      remainderA = (remainderA + (a[i] - '0')) % m;
      remainderB = (remainderB + (b[i] - '0')) % m;
      if ((a[i] - '0') != d) equalA = 0;
      if ((b[i] - '0') != d) equalB = 0;
      currentIndex = 1 - currentIndex;
    }
    for (int r = 0; r < m; r++) {
      resultsBetween[currentIndex][r] = resultsBetween[currentIndex][r] % p;
    }
  }
  if (remainderA == 0) resultsBetween[currentIndex][0] += equalA;
  if ((areABequal == false) && (remainderB == 0))
    resultsBetween[currentIndex][0] += equalB;
  std::cout << (resultsBetween[currentIndex][0]) % p;
}
