#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int m, d, n;
int dp[2005][2][2][2005];
string a, b;
int calc(int ind, int t1, int t2, int sum) {
  if (ind == n) return (sum == 0);
  if (dp[ind][t1][t2][sum] != -1) return dp[ind][t1][t2][sum];
  int k1 = (t1) ? (a[ind] - '0') : 0;
  int k2 = (t2) ? (b[ind] - '0') : 9;
  int res = 0;
  if (ind % 2) {
    if (k1 <= d && d <= k2)
      (res += calc(ind + 1, (t1 & (d == k1)), (t2 & (d == k2)),
                   (sum * 10 + d) % m)) %= MOD;
  } else {
    for (int i = k1; i <= k2; ++i) {
      if (i == d) continue;
      (res += calc(ind + 1, (t1 & (i == k1)), (t2 & (i == k2)),
                   (sum * 10 + i) % m)) %= MOD;
    }
  }
  return (dp[ind][t1][t2][sum] = res);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> d >> a >> b;
  n = a.length();
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      for (int k = 0; k < 2; ++k)
        for (int t = 0; t < 2; ++t) dp[i][k][t][j] = -1;
  cout << calc(0, 1, 1, 0);
  return 0;
}
