#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long m, d, n;
string a, b, vec;
long long dp[2000][2][2000];
long long noOfMagicNumbers(long long ind, long long flg, long long num) {
  if (ind == n) {
    return (num == 0);
  }
  if (dp[ind][flg][num] != -1) return dp[ind][flg][num];
  if (ind % 2 == 1) {
    if (d < (vec[ind] - '0'))
      return dp[ind][flg][num] =
                 noOfMagicNumbers(ind + 1, 1, (num * 10 + d) % m);
    else if (d == (vec[ind] - '0') || flg == 1)
      return dp[ind][flg][num] =
                 noOfMagicNumbers(ind + 1, flg, (num * 10 + d) % m);
    else
      return 0;
  }
  long long limit = 9;
  if (flg == 0) limit = vec[ind] - '0';
  long long ans = 0;
  long long i = 0;
  if (ind == 0) i = 1;
  for (; i <= limit; i++) {
    if (i == d) continue;
    if (i < limit)
      ans = (ans +
             noOfMagicNumbers(ind + 1, 1, ((num * 10) % 1000000007 + i) % m)) %
            1000000007;
    else
      ans = (ans + noOfMagicNumbers(ind + 1, flg,
                                    ((num * 10) % 1000000007 + i) % m)) %
            1000000007;
  }
  return dp[ind][flg][num] = ans;
}
bool isMagic(string x) {
  long long n = x.size();
  long long re = 0;
  for (long long i = 0; i < n; i++) {
    if (i % 2 == 1) {
      if (d != (x[i] - '0')) return false;
    } else {
      if (d == (x[i] - '0')) return false;
    }
    re = ((re * 10) % 1000000007 + (x[i] - '0')) % m;
  }
  if (re != 0) return false;
  return true;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> m >> d;
  cin >> a;
  cin >> b;
  n = b.size();
  memset(dp, -1, sizeof(dp));
  vec = b;
  long long ans1 = noOfMagicNumbers(0, 0, 0);
  n = vec.size();
  memset(dp, -1, sizeof(dp));
  vec = a;
  long long ans2 = noOfMagicNumbers(0, 0, 0);
  if (isMagic(a)) ans2 = (ans2 - 1 + 1000000007) % 1000000007;
  cout << (ans1 - ans2 + 1000000007) % 1000000007 << "\n";
  return 0;
}
