#include <bits/stdc++.h>
using namespace std;
long long oll = 0;
bool comp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}
string a, b, str;
long long len, d, m, dp[2009][2][2009];
long long fnc(int pos, int sfl, int rem) {
  if (pos >= len) {
    if (!rem) {
      return 1;
    }
    return 0;
  }
  long long &ret = dp[pos][sfl][rem];
  if (ret != -1) return ret;
  int t = pos;
  ret = 0;
  int mx = 9, st;
  if (!sfl) mx = str[pos] - '0';
  if (pos == 0)
    st = 1;
  else
    st = 0;
  if (pos % 2 == 1) {
    if (d <= mx)
      ret += fnc(pos + 1, d < mx || sfl, (rem * 10 + d) % m) % 1000000007;
  } else {
    for (int l = st; l <= mx; l++) {
      if (l == d) continue;
      ret += fnc(pos + 1, l < mx || sfl, (rem * 10 + l) % m) % 1000000007;
    }
  }
  return ret % 1000000007;
}
int sum(string t) {
  str = t;
  memset(dp, -1, sizeof(dp));
  len = str.size();
  return fnc(0, 0, 0);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> d;
  cin >> a >> b;
  string save = a;
  string temp = a;
  if (a.size() == 1 && a[0] == '0') {
  } else {
    for (int i = temp.size() - 1; i >= 0; i--) {
      int t = temp[i] - '0';
      if (t != 0) {
        temp[i] = (t - 1) + '0';
        break;
      } else {
        temp[i] = '9';
      }
    }
  }
  int st = 0;
  a.clear();
  if (temp.size() == 1) {
    a = temp;
  } else {
    while (temp[st] == '0') st++;
    for (int i = st; i < temp.size(); i++) {
      a += temp[i];
    }
  }
  long long sa = 0, sb = 0;
  if (a.size() < save.size())
    sa = 0;
  else
    sa = sum(a);
  sb = sum(b);
  int ans = sb - sa;
  if (ans < 0) ans += 1000000007;
  cout << ans << "\n";
  return 0;
}
