#include <bits/stdc++.h>
using namespace std;
int mod(int a) {
  a -= (a / 1000000007) * 1000000007;
  if (a < 0) return a + 1000000007;
  return a;
}
int mod(int a, int m) {
  a -= (a / m) * m;
  if (a < 0) return a + m;
  return a;
}
int solve(int m, int d, char* l, int f) {
  vector<vector<int> > dOdd(strlen(l) + 1, vector<int>(m, 0));
  vector<vector<int> > dEven(strlen(l) + 1, vector<int>(m, 0));
  dOdd[0][0] = 1;
  dEven[0][0] = 1;
  for (int i = 1; i <= strlen(l); ++i) {
    for (int j = 0; j < m; ++j) {
      if (i & 1)
        dOdd[i][(j * 10 + d) % m] =
            mod(dOdd[i][(j * 10 + d) % m] + dOdd[i - 1][j]);
      else
        dEven[i][(j * 10 + d) % m] =
            mod(dEven[i][(j * 10 + d) % m] + dEven[i - 1][j]);
      for (int k = 0; k < 10; ++k) {
        if ((i & 1) && k != d)
          dEven[i][(j * 10 + k) % m] =
              mod(dEven[i][(j * 10 + k) % m] + dEven[i - 1][j]);
        else if (((i & 1) == 0) && k != d)
          dOdd[i][(j * 10 + k) % m] =
              mod(dOdd[i][(j * 10 + k) % m] + dOdd[i - 1][j]);
      }
    }
  }
  int r = 0, flag = f, ret = 0;
  for (int i = 0; i < strlen(l); ++i) {
    int p = 1;
    for (int j = i + 1; j < strlen(l); ++j) p = (p * 10) % m;
    if ((i & 1) == 0) {
      for (int j = 0; j < l[i] - '0'; ++j) {
        if (j == d) continue;
        ret = mod(ret + dOdd[strlen(l) - i - 1][mod(m - (r + p * j), m)]);
      }
      if (l[i] - '0' == d) {
        flag = 0;
        break;
      }
    } else {
      if (d < l[i] - '0')
        ret = mod(ret + dEven[strlen(l) - i - 1][mod(m - (r + p * d), m)]);
      if (l[i] - '0' != d) {
        flag = 0;
        break;
      }
    }
    r = (r + p * (l[i] - '0')) % m;
  }
  if (r != 0) flag = 0;
  return ret + flag;
}
int main() {
  int m, d;
  char a[2000 + 1], b[2000 + 1];
  scanf("%d%d", &m, &d);
  scanf("%s%s", a, b);
  printf("%d\n", (mod(solve(m, d, b, 1) - solve(m, d, a, 0))));
  return 0;
}
