#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
int m, d, L;
int bit[2001];
long long dp[2001][2001];
void add(long long &x, long long y) { x = (x + y) % MOD; }
long long DFS(int pos, int preyu, bool yes) {
  if (pos == L) return preyu == 0;
  if (!yes && dp[pos][preyu] != -1) return dp[pos][preyu];
  long long ans = 0;
  int End = yes ? bit[pos] : 9;
  for (int i = 0; i <= End; i++) {
    if (pos % 2 == 0 && i == d) continue;
    if (pos % 2 == 1 && i != d) continue;
    add(ans, DFS(pos + 1, (preyu * 10 + i) % m, yes && i == End));
  }
  if (!yes) dp[pos][preyu] = ans;
  return ans;
}
long long Count(string str) {
  int len = str.size();
  int cnt = 0;
  for (int i = 0; i < len; i++) bit[i] = str[i] - '0';
  return DFS(0, 0, 1);
}
bool judge(string str) {
  int len = str.size();
  int yu = 0;
  for (int i = 0; i < len; i++) {
    int v = str[i] - '0';
    yu = yu * 10 + v;
    yu %= m;
    if ((i + 1) & 1 && v == d) return false;
    if (i & 1 && v != d) return false;
  }
  return yu == 0;
}
int main() {
  memset(dp, (-1), sizeof(dp));
  cin >> m >> d;
  string a, b;
  cin >> a >> b;
  L = a.size();
  cout << (Count(b) - Count(a) + judge(a) + MOD) % MOD << endl;
  return 0;
}
