#include <bits/stdc++.h>
using namespace std;
string s, ss;
int m, d, mod = (int)1e9 + 7;
long long mem[2007][2007][2][2];
long long solve(int i = 0, int mo = 0, int f1 = 0, int f2 = 0) {
  if (i == s.size()) return !mo;
  long long &ret = mem[i][mo][f1][f2];
  if (~ret) return ret;
  int l = s[i] - '0', r = ss[i] - '0';
  if (f1) l = 0;
  if (f2) r = 9;
  ret = 0;
  if (i & 1) {
    if (l <= d && r >= d)
      ret = solve(i + 1, (mo * 10 + d) % m, f1 | (d > l), f2 | (r > d));
  } else {
    for (int j = l; j <= r; j++) {
      if (j == d) continue;
      ret += solve(i + 1, (mo * 10 + j) % m, (l < j) | f1, (r > j) | f2);
      ret %= mod;
    }
  }
  return ret % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> m >> d;
  cin >> s >> ss;
  memset(mem, -1, sizeof(mem));
  cout << solve() << endl;
}
