#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const long long inf = 2e9 + 10;   template <typename T1, typename T2>   static void relax(T1 &x, T2 y) {     if (x > y) x = y;   }   template <typename T1, typename T2>   static void gain(T1 &x, T2 y) {     if (x < y) x = y;   }   long long powmod(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   inline void add(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   inline void sub(int &x, int y) {     x -= y;     if (x < 0) x += mod;   }   const int maxl = 2e3 + 3;   int m, d;   string a, b;   int dp[maxl][maxl][2];   int solve(string s) {     int n = (int)s.length();     for (int(i) = 0; (i) < (int)(n + 1); ++(i))       for (int(j) = 0; (j) < (int)(m); ++(j))         for (int(k) = 0; (k) < (int)(2); ++(k)) dp[i][j][k] = 0;     dp[0][0][1] = 1;     for (int(i) = 0; (i) < (int)(n); ++(i))       for (int(j) = 0; (j) < (int)(m); ++(j))         for (int(k) = 0; (k) < (int)(2); ++(k))           for (int dgt = 0; dgt <= (k ? int(s[i] -  0 ) : 9); ++dgt) {             if ((i & 1) && dgt != d) continue;             if (!(i & 1) && dgt == d) continue;             int ni = i + 1;             int nj = ((j * 10 + dgt) % m);             int nk = k && (dgt == int(s[i] -  0 ));             add(dp[ni][nj][nk], dp[i][j][k]);           }     int ans = 0;     for (int(k) = 0; (k) < (int)(2); ++(k)) add(ans, dp[n][0][k]);     return ans;   }   bool ok(string s) {     int n = (int)s.length();     int rem = 0;     for (int(i) = 0; (i) < (int)(n); ++(i)) {       int dgt = int(s[i] -  0 );       if ((i & 1) && dgt != d) return false;       if (!(i & 1) && dgt == d) return false;       rem = (rem * 10 + dgt) % m;     }     return !rem;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> m >> d;     cin >> a;     cin >> b;     int ans = 0;     add(ans, solve(b));     sub(ans, solve(a));     add(ans, ok(a));     cout << ans <<   n ;     return 0;   }   