#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238462643383;
int Ceil(int a, int b) {
  if (a % b == 0)
    return a / b;
  else
    return (a / b) + 1;
}
bool comp(pair<int, int> i1, pair<int, int> i2) {
  return (min(i1.first, i1.second) < min(i2.first, i2.second));
}
int sumfind(int i) {
  int sum = 0;
  while (i > 0 && sum <= 10) {
    sum += i % 10;
    i = i / 10;
  }
  return sum;
}
long long cn(int pos, int mod, int f, vector<vector<vector<long long>>>& dp,
             vector<int>& num, int d, int m) {
  long long p = 1000000007;
  if (pos == num.size()) {
    return mod == 0;
  } else if (dp[pos][mod][f] != -1)
    return dp[pos][mod][f];
  if (pos % 2 == 1) {
    if (f == 0) {
      if (d > num[pos]) {
        dp[pos][mod][f] = 0;
      } else if (d == num[pos])
        dp[pos][mod][f] = cn(pos + 1, (10 * mod + d) % m, 0, dp, num, d, m);
      else
        dp[pos][mod][f] = cn(pos + 1, (10 * mod + d) % m, 1, dp, num, d, m);
    } else {
      dp[pos][mod][f] = cn(pos + 1, (10 * mod + d) % m, 1, dp, num, d, m);
    }
    return dp[pos][mod][f];
  }
  int lim = 9;
  if (f == 0) {
    lim = num[pos];
  }
  long long res = 0;
  for (int i = 0; i <= lim; i++) {
    if (i == d) continue;
    if (f == 0 && i == lim) {
      res += cn(pos + 1, (10 * mod + i) % m, 0, dp, num, d, m);
    } else {
      res += cn(pos + 1, (10 * mod + i) % m, 1, dp, num, d, m);
    }
    res %= p;
  }
  dp[pos][mod][f] = res;
  return res;
}
long long solve(string b, int m, int d) {
  vector<int> num;
  for (int i = 0; i < b.length(); i++) {
    num.push_back(b[i] - '0');
  }
  vector<vector<vector<long long>>> dp(
      num.size(), vector<vector<long long>>(m, vector<long long>(2, -1)));
  return cn(0, 0, 0, dp, num, d, m);
}
int is(string a, int m, int d) {
  int count = 0;
  for (int i = 0; i < a.length(); i++) {
    if (i & 1 && (a[i] - '0') != d) return 0;
    if (i % 2 == 0 && (a[i] - '0') == d) return 0;
    count = (count * 10 + a[i] - '0') % m;
  }
  return count == 0;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int m, d;
  cin >> m >> d;
  string a;
  cin >> a;
  string b;
  cin >> b;
  cout << (1000000007 + solve(b, m, d) - solve(a, m, d) + is(a, m, d)) %
              1000000007
       << '\n';
  return 0;
}
