#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
long long int dp[2007][2007][2];
int n;
string a, b;
void getdigits(string a, vector<int>& dig) {
  for (int i = 0; i < n; i++) {
    dig.push_back(a[i] - '0');
  }
}
int call(int idx, int rem, int tight, int d, vector<int>& dig, int m) {
  if (idx == n) {
    if (rem == 0) return 1;
    return 0;
  }
  if (dp[idx][rem][tight] != -1 && !tight) return dp[idx][rem][tight];
  int k = tight ? (dig[idx]) : 9;
  int res = 0L;
  for (int i = 0; i <= k; i++) {
    if ((idx & 1) && i != d) continue;
    if (!(idx & 1) && i == d) continue;
    int newtight = (dig[idx] == i) ? tight : 0;
    res = (res + call(idx + 1, (rem * 10 + i) % m, newtight, d, dig, m)) % mod;
  }
  if (tight == 0) dp[idx][rem][tight] = res;
  return res;
}
void sub_one(long long int len) {
  for (int i = len - 1; i >= 0; i--) {
    if (a[i] == '0')
      a[i] = '9';
    else {
      a[i]--;
      break;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int m, d;
  cin >> m >> d;
  cin >> a >> b;
  n = a.size();
  sub_one(n);
  vector<int> dig;
  getdigits(a, dig);
  memset(dp, -1, sizeof(dp));
  int ans1 = call(0, 0, 1, d, dig, m);
  memset(dp, -1, sizeof(dp));
  dig.clear();
  getdigits(b, dig);
  int ans2 = call(0, 0, 1, d, dig, m);
  int ans = (ans2 - ans1 + mod) % mod;
  cout << ans;
}
