#include <bits/stdc++.h>
using namespace std;
long long len, m, d, MOD = 1000000007;
long long dp[2002][3][2002];
char a[3000], b[3000];
long long dfs(int pos, int first, int mod, int limit) {
  if (pos < 0) {
    if (first == 2 || mod == 0)
      return 1;
    else
      return 0;
  }
  if (!limit && dp[pos][first][mod] > -1) return dp[pos][first][mod];
  long long ret = 0, i, end;
  if (limit)
    end = a[pos] - '0';
  else
    end = 9;
  if (first < 2 && (pos + first) % 2 == 1) {
    if (limit && a[pos] - '0' < d)
      return 0;
    else
      ret = dfs(pos - 1, first, (mod * 10 + d) % m, limit && a[pos] - '0' == d);
  } else {
    for (i = 0; i <= end; i++) {
      int temp;
      if (i == d) continue;
      if (first == 2 && i == 0)
        temp = 2;
      else if (first < 2)
        temp = first;
      else
        temp = pos % 2;
      ret = (ret + dfs(pos - 1, temp, (mod * 10 + i) % m, limit && i == end)) %
            MOD;
    }
  }
  if (!limit) dp[pos][first][mod] = ret;
  return ret;
}
int main() {
  long long ans, ans1, ans2;
  memset(dp, -1, sizeof(dp));
  cin >> m >> d;
  cin >> a;
  len = strlen(a);
  int add = 1;
  int x = 0;
  for (int i = 0; i < len; i++) {
    x = (x * 10 + a[i] - '0') % m;
    if (i % 2 == 1 && a[i] - '0' != d)
      add = 0;
    else if (i % 2 == 0 && a[i] - '0' == d)
      add = 0;
  }
  if (x > 0) add = 0;
  int tot = 0;
  for (int i = len - 1; i >= 0; i--) {
    b[tot++] = a[i];
  }
  for (int i = 0; i < len; i++) a[i] = b[i];
  ans1 = dfs(len - 1, 2, 0, 1);
  cin >> a;
  len = strlen(a);
  tot = 0;
  for (int i = len - 1; i >= 0; i--) {
    b[tot++] = a[i];
  }
  for (int i = 0; i < len; i++) a[i] = b[i];
  ans2 = dfs(len - 1, 2, 0, 1);
  ans = (ans2 - ans1 + MOD + add) % MOD;
  cout << ans << endl;
  return 0;
}
