#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
vector<int> digit(long long n) {
  vector<int> v;
  while (n) {
    v.push_back(n % 10);
    n /= 10;
  }
  return v;
}
long long dp[2001][2001][2][2];
long long m, d;
long long solve(int id, long long sum, int y, string &digit, int z = 0) {
  if (id < 0) return sum == 0;
  if (dp[id][sum][y][z] != -1) return dp[id][sum][y][z];
  long long ways = 0;
  int k = y ? digit[id] - '0' : 9;
  if (z) {
    if (y && k < d) return 0;
    int ny = (digit[id] - '0' == d) ? y : 0;
    return dp[id][sum][y][z] =
               solve(id - 1, (sum * 10 + d) % m, ny, digit, z ^ 1) %
               (long long)1000000007;
  }
  for (int i = 0; i <= k; ++i) {
    if (i == d) continue;
    int ny = (digit[id] - '0' == i) ? y : 0;
    ways = (ways + solve(id - 1, (sum * 10 + i) % m, ny, digit, z ^ 1)) %
           (long long)1000000007;
  }
  if (!y) dp[id][sum][y][z] = ways;
  return ways;
}
int check(string &second) {
  reverse(second.begin(), second.end());
  int y = 0, x = 0;
  for (int i = 0; i < second.size(); ++i) {
    x = (x * 10 + second[i] - '0') % m;
    if (second[i] - '0' == d && i % 2 == 0) return 0;
    if (second[i] - '0' != d && i % 2 == 1) return 0;
  }
  if (x) return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  string a, b;
  cin >> m >> d >> a >> b;
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  memset(dp, -1, sizeof dp);
  long long x1 = 0, x2 = 0;
  x1 = solve(a.size() - 1, 0, 1, a, 0);
  memset(dp, -1, sizeof dp);
  x2 = solve(b.size() - 1, 0, 1, b, 0) + check(a);
  long long ans = (x2 - x1) % (long long)1000000007;
  if (ans < 0) ans += (long long)1000000007;
  cout << ans;
  return 0;
}
