#include <bits/stdc++.h>
using namespace std;
int mod = 1000000000 + 7;
class Solution {
  int m, d;
  vector<int> nums;
  int mod = 1000000000 + 7;
  vector<vector<vector<int>>> dp;

 public:
  Solution(int m, int d) {
    this->m = m;
    this->d = d;
  }
  int recDp(int pos, int seq, int flg) {
    if (pos == nums.size()) {
      if (seq % m == 0) {
        return 1;
      } else {
        return 0;
      }
    }
    if (dp[pos][seq][flg] != -1) return dp[pos][seq][flg];
    int res = 0;
    int lmt;
    if (flg == 0) {
      lmt = nums[pos];
    } else {
      lmt = 9;
    }
    for (int i = 0; i <= lmt; i++) {
      int nxtflg = flg;
      if (pos % 2 == 1 && i != d) continue;
      if (pos % 2 == 0 && i == d) continue;
      if (flg == 0 && i < lmt) nxtflg = 1;
      res = (res + recDp(pos + 1, (seq * 10 + i) % m, nxtflg)) % mod;
    }
    dp[pos][seq][flg] = res;
    return res;
  }
  int solve(string b) {
    nums.clear();
    for (int i = 0; i < b.size(); i++) {
      nums.push_back(b[i] - '0');
    }
    int l = nums.size();
    int flg = 2;
    dp = vector<vector<vector<int>>>(
        l, vector<vector<int>>(m + 1, vector<int>(flg, -1)));
    return recDp(0, 0, 0);
  }
  int isgood(string sa) {
    int l = sa.size();
    for (int i = 0; i < sa.size(); i++) {
      if (i % 2 == 0 && sa[i] == '0' + d) return 0;
      if (i % 2 == 1 && sa[i] != '0' + d) return 0;
    }
    if ((sa[l - 1] - '0') % m != 0) return 0;
    return 1;
  }
};
int main() {
  int m, d;
  string a, b;
  cin >> m >> d;
  cin >> a >> b;
  Solution s(m, d);
  int tillb = s.solve(b);
  int tilla = s.solve(a);
  cout << (tillb - tilla + mod) % mod + s.isgood(a);
  return 0;
}
