#include <bits/stdc++.h>
const long double EPS = 1e-10;
const long long int MOD = 1000000007ll;
const long long int mod1 = 1000000009ll;
const long long int mod2 = 1100000009ll;
int INF = 2147483645;
long long int INFINF = 9223372036854775807;
int debug = 0;
using namespace std;
void print(int a[], int s, int e) {
  for (int i = s; i <= e; i++) cout << a[i] << " ";
  cout << "\n";
}
void print(vector<int> &v, int s, int e) {
  for (int i = s; i <= e; i++) cout << v[i] << " ";
  cout << "\n";
}
void print(vector<int> &v) {
  for (int x : v) cout << x << " ";
  cout << "\n";
}
long long int bit_count(long long int _x) {
  long long int _ret = 0;
  while (_x) {
    if (_x % 2 == 1) _ret++;
    _x /= 2;
  }
  return _ret;
}
long long int bit(long long int _mask, long long int _i) {
  return (_mask & (1 << _i)) == 0 ? 0 : 1;
}
long long int powermod(long long int _a, long long int _b, long long int _m) {
  long long int _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a) % _m;
    _b /= 2;
    _a = (_a * _a) % _m;
  }
  return _r;
}
long long int add(long long int a, long long int b, long long int m = MOD) {
  long long int x = a + b;
  while (x >= m) x -= m;
  return x;
}
long long int sub(long long int a, long long int b, long long int m = MOD) {
  long long int x = a - b;
  while (x < 0) x += m;
  return x;
}
long long int mul(long long int a, long long int b, long long int m = MOD) {
  long long int x = a * b;
  x %= m;
  return x;
}
int m, d;
string a, b;
long long int dp[2010][2010][2][2];
bool vis[2010][2010][2][2];
long long int solve(int l, int r, int a1, int b1) {
  if (l == a.size()) return (r == 0) ? 1 : 0;
  if (vis[l][r][a1][b1]) return dp[l][r][a1][b1];
  vis[l][r][a1][b1] = true;
  for (int i = 0; i < 10; i++) {
    if (l % 2 == 0 && i == d) continue;
    if (l % 2 == 1 && i != d) continue;
    if (a1 == 0 && i < a[l] - '0') continue;
    if (b1 == 0 && i > b[l] - '0') continue;
    dp[l][r][a1][b1] = add(
        dp[l][r][a1][b1], solve(l + 1, (10 * r + i) % m, a1 || (i > a[l] - '0'),
                                b1 || (i < b[l] - '0')));
  }
  return dp[l][r][a1][b1];
}
int main() {
  srand(time(NULL));
  cin >> m >> d;
  cin >> a >> b;
  cout << solve(0, 0, 0, 0);
  return 0;
}
