#include <bits/stdc++.h>
using namespace std;
const int mo = 1e9 + 7;
int m, num, n, low[2010], up[2010];
long long dp[2010][2010][3], ans;
char a[2010], b[2010];
long long work() {
  for (int i = 1; i <= n; i++) up[i] = a[i] - '0', low[i] = b[i] - '0';
  if (low[1] == up[1]) {
    if (low[1] == num) return 0;
    dp[1][up[1] % m][1]++;
  } else {
    for (int i = low[1] + 1; i <= up[1] - 1; i++)
      if (i != num) dp[1][i % m][0]++;
    if (low[1] != num) dp[1][low[1] % m][2]++;
    if (up[1] != num) dp[1][up[1] % m][1]++;
  }
  for (int i = 1; i <= n - 1; i++)
    for (int j = 0; j < m; j++)
      if ((i + 1) & 1) {
        for (int k = 0; k <= 9; k++)
          if (k != num) {
            dp[i + 1][(10 * j + k) % m][0] =
                (dp[i + 1][(10 * j + k) % m][0] + dp[i][j][0]) % mo;
            if (k == up[i + 1])
              dp[i + 1][(10 * j + k) % m][1] =
                  (dp[i + 1][(10 * j + k) % m][1] + dp[i][j][1]) % mo;
            if (k < up[i + 1])
              dp[i + 1][(10 * j + k) % m][0] =
                  (dp[i + 1][(10 * j + k) % m][0] + dp[i][j][1]) % mo;
            if (k == low[i + 1] &&
                (low[i + 1] != up[i + 1] ||
                 (low[i + 1] == up[i + 1] && low[i] != up[i])))
              dp[i + 1][(10 * j + k) % m][2] =
                  (dp[i + 1][(10 * j + k) % m][2] + dp[i][j][2]) % mo;
            if (k > low[i + 1])
              dp[i + 1][(10 * j + k) % m][0] =
                  (dp[i + 1][(10 * j + k) % m][0] + dp[i][j][2]) % mo;
          }
      } else {
        dp[i + 1][(10 * j + num) % m][0] =
            (dp[i + 1][(10 * j + num) % m][0] + dp[i][j][0]) % mo;
        if (up[i + 1] == num)
          dp[i + 1][(10 * j + num) % m][1] =
              (dp[i + 1][(10 * j + num) % m][1] + dp[i][j][1]) % mo;
        if (up[i + 1] > num)
          dp[i + 1][(10 * j + num) % m][0] =
              (dp[i + 1][(10 * j + num) % m][0] + dp[i][j][1]) % mo;
        if (low[i + 1] == num && (low[i + 1] != up[i + 1] ||
                                  (low[i + 1] == up[i + 1] && low[i] != up[i])))
          dp[i + 1][(10 * j + num) % m][2] =
              (dp[i + 1][(10 * j + num) % m][2] + dp[i][j][2]) % mo;
        if (low[i + 1] < num)
          dp[i + 1][(10 * j + num) % m][0] =
              (dp[i + 1][(10 * j + num) % m][0] + dp[i][j][2]) % mo;
      }
  for (int i = 0; i < 3; i++) ans = (ans + dp[n][0][i]) % mo;
  return ans;
}
int main() {
  scanf("%d%d", &m, &num);
  scanf("%s", b + 1);
  scanf("%s", a + 1);
  n = strlen(a + 1);
  printf("%lld\n", work());
  return 0;
}
