#include <bits/stdc++.h>
using namespace std;
int m, d;
long long dp[2005][2005][3];
long long solve(string &second, int i, int md, int issmall) {
  if (i == second.size()) {
    return !md;
  }
  long long &ret = dp[i][md][issmall];
  if (ret != -1) return ret;
  int ch = second[i] - '0';
  ret = 0;
  if (i % 2 == 0) {
    if (issmall) {
      for (int j = 0; j <= 9; j++) {
        if (j != d)
          ret = (ret + solve(second, i + 1, (md * 10 + j) % m, 1)) % 1000000007;
      }
      return ret;
    } else {
      for (int j = 0; j <= ch; j++) {
        if (j < ch && j != d)
          ret = (ret + solve(second, i + 1, (md * 10 + j) % m, 1)) % 1000000007;
        else if (j == ch && j != d)
          ret = (ret + solve(second, i + 1, (md * 10 + j) % m, 0)) % 1000000007;
      }
    }
  } else {
    if (issmall) {
      ret = solve(second, i + 1, (md * 10 + d) % m, 1);
    } else {
      if (d < ch)
        ret = solve(second, i + 1, (md * 10 + d) % m, 1);
      else if (d == ch)
        ret = solve(second, i + 1, (md * 10 + d) % m, 0);
    }
  }
  return ret;
}
long long okay(string second) {
  int mul = 0;
  int okay1 = 1, okay2 = 1;
  for (int i = 0; i < second.size(); i++) {
    if (i % 2) {
      if (second[i] - '0' != d) okay1 = 0;
    } else {
      if (second[i] - '0' == d) okay2 = 0;
    }
    mul = (mul * 10 + second[i] - '0') % m;
  }
  return (!mul && okay1 && okay2);
}
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  };
  cin >> m >> d;
  string a, b;
  cin >> a >> b;
  long long ans1 = 0, ans2 = 0;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= 9; i++) {
    int ch = a[0] - '0';
    if (i < ch && i != d)
      ans1 = (ans1 + solve(a, 1, i % m, 1)) % 1000000007;
    else if (ch == i && i != d)
      ans1 = (ans1 + solve(a, 1, i % m, 0)) % 1000000007;
  }
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= 9; i++) {
    int ch = b[0] - '0';
    if (i < ch && i != d)
      ans2 = (ans2 + solve(b, 1, i % m, 1)) % 1000000007;
    else if (ch == i && i != d)
      ans2 = (ans2 + solve(b, 1, i % m, 0)) % 1000000007;
  }
  cout << (((ans2 - ans1) % 1000000007 + 1000000007) % 1000000007 + okay(a)) %
              1000000007
       << endl;
}
