#include <bits/stdc++.h>

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foreach(it, v) for(__typeof((v).begin()) it=(v).begin(); it != (v).end(); ++it)
#define meta __FUNCTION__,__LINE__

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

void tr(){cout << endl;}
template<typename S, typename ... Strings>
void tr(S x, const Strings&... rest){cout<<x<<' ';tr(rest...);}

typedef long long ll;
typedef pair<int,int> pii;

const int N = 1001000;
const int M = 26;

struct suffixAutomaton{
	struct state{
		int len, link;
		int next[M];
		ll cnt;

		bool terminal;	// by default, empty string is a suffix

		state(){
			len = 0, link = -1, cnt = 0;
			terminal = false;
			for(int i = 0; i < M; i++) next[i] = -1;
		}
	};

	state st[N*2];
	int sz, last;
	char offset = 'a';	// Careful!

	suffixAutomaton(string &s){
		int l = s.length();

		for(int i = 0; i < 2*l; i++) st[i] = state();

		sz = 1, last = 0;
		st[0].len = 0;
		st[0].link = -1;

		for(int i = 0; i < l; i++)
			addChar(s[i] - offset);

		for(int i = last; i != -1; i = st[i].link) st[i].terminal = true;
	}

	void addChar(int c){
		int cur = sz++; assert(cur < N*2);
		st[cur].len = st[last].len + 1;
		st[cur].cnt = 1;

		int p = last;
		while(p != -1 and st[p].next[c] == -1){
			st[p].next[c] = cur;
			p = st[p].link;
		}

		last = cur;

		if(p == -1){
			st[cur].link = 0; return;
		}

		int q = st[p].next[c];

		if(st[q].len == st[p].len + 1){
			st[cur].link = q; return;
		}

		int clone = sz++;

		for(int i = 0; i < M; i++) st[clone].next[i] = st[q].next[i];
		st[clone].link = st[q].link;
		st[clone].len = st[p].len + 1;
		st[clone].cnt = 0;

		while(p != -1 and st[p].next[c] == q){
			st[p].next[c] = clone;
			p = st[p].link;
		}

		st[q].link = st[cur].link = clone;

		return;
	}

	bool contains(string &t){
		int cur = 0;
		for(int i = 0; i < t.length(); i++){
			cur = st[cur].next[t[i] - offset];
			if(cur == -1) return false;
		}
		return true;
	}

	// alternatively, compute the number of paths in a DAG
	// since each substring corresponds to one unique path in SA
	ll numberOfSubstrings(){
		ll res = 0;
		for(int i = 1; i < sz; i++) res += st[i].len - st[st[i].link].len;
		return res;
	}

	ll h[2*N];
	ll base = 29;
	ll pr = 1e9 + 7;
	set<ll> done;
	ll p[2*N];

	void numberOfOccPreprocess(){
		vector<pii> v;
		for(int i = 1; i < sz; i++) v.pb(mp(st[i].len, i));

		sort(v.begin(), v.end(), greater<pii>());

		for(int i = 0; i < sz-1; i++){
			int suf = st[v[i].se].link;
			st[suf].cnt += st[v[i].se].cnt;
		}

		p[0] = 1;
		for(int i = 1; i < 2*N; i++){
			p[i] = (p[i-1] * base) % pr;
		}
	}

	ll numberOfOcc(string &t){
		ll res = 0;
		int cur = 0;
		int l = 0, m = t.length();
		done.clear();

		string tmp = t+t;
		h[0] = 0;
		for(int i = 1; i <= 2*m; i++){
			h[i] = ((h[i-1] * base) + (tmp[i-1] - offset + 1)) % pr;
//			tr(i, h[i]);
		}

		for(int i = 0; i < m; i++){
			while(cur != 0 and st[cur].next[t[i] - offset] == -1){
				cur = st[cur].link;
				l = st[cur].len;
			}
			int nxt = st[cur].next[t[i] - offset];

			if(nxt == -1) nxt = 0, l = 0;
			else l++;
			cur = nxt;
		}

		if(l == m){
			res += st[cur].cnt;
//			tr(meta, h[m]);
			done.insert(h[m]);
		}

		for(int i = 0; i < m-1; i++){
			while(cur != 0 and st[cur].next[t[i] - offset] == -1){
				cur = st[cur].link;
				l = st[cur].len;
			}
			int nxt = st[cur].next[t[i] - offset];
			if(nxt == -1) nxt = 0, l = 0;
			else l++;
			cur = nxt;

			if(l > m){
				if(l-1 == st[st[cur].link].len)
					cur = st[cur].link;
				l--;
			}

			ll v1 = h[m+i+1];
			ll v2 = (h[i+1] * p[m]) % pr;
			v1 = (v1 - v2 + pr) % pr;

//			tr(meta, i, v1, v2, tmp, l, p[m]);

			if(l == m and !done.count(v1)){
				res += st[cur].cnt;
				done.insert(v1);
			}

		}

		return res;
	}

};

string s;
string t;

int main(){ _
	cin >> s;
	suffixAutomaton *suf = new suffixAutomaton(s);
	suf->numberOfOccPreprocess();

	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> t;
		cout << suf->numberOfOcc(t) << '\n';
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const big mod = 10000000007;
typedef long long big big;

big m,d;
string a,b;
big add(big a, big b)                 {  return (a+b)%mod;}
void inc(big &a, big b)              {      a = add(a,b);            }

#define forn(i,n) for(big i = 0;i<(big)n;i++)

 big sub(big a, big b){
                                   if(a<b) swap(a,b);
                                   return (a-b)%mod;}
 void tru(big &a, big b) { a = sub(a,b);}

const big N = 2005;

big z[N][N][2];      ///zijk  so cai thoa man voi do dai i , remain j, k : prefix
big solve(string s){
    ///buoc 1: cho tat ca bang 0 tru so 0
    big n = s.size();
    memset(z, 0, sizeof z);
    z[0][0][1] = 1;

    forn(i,n)
      forn(j,m)
        forn(k,2)
          for(big p = 0;p<=( k?(big) s[i] - '0': 9);p++){
              if((i&1)    &&(p!=d)) continue;           ///
              if((!(i&1)) &&p==d) continue;
              if(!i&&!p)       continue;

              big ni = i+1;
              big nj = (j*10+ p)%m;
              big nk = (k&&(p ==(big) (s[i] -'0')));
             inc(z[ni][nj][nk], z[i][j][k]);
          }
    big ans = 0;
    forn(k,2) inc(ans, z[n][0][k]);
    return ans;
}
bool good(string a){
    big remain = 0;
    forn(i,a.size()){
         big p = big(a[i] - '0');
         remain = (remain*10 + p)%m;
         if((i&1)&&p!=d) return 0;
         if((!(i&1))&&p==d) return 0;
    }
    return !remain;
}
void check(){
   big ans = 0;
   inc(ans, solve(b));
    tru(ans, solve(a));
    inc(ans, good(a));
    cout << ans << endl;
}
big main(){
    a.clear();

    cin>> m>> d;
    cin>> a>>b;
    check();
}
///2 6 10 99
///43 3 587 850
///760 014 418
///tai sao no lai ra am la sao


#include<bits/stdc++.h>
using namespace std;
#define          mp                make_pair
#define          pb                push_back
typedef long long int big;
#define         x                  first
#define         y                  second
#define         forn(i, n)         for(int i = 0;i<n;i++)
#define         nfor(i, n)         for(int i = n-1;i>=0;i--)
typedef pair<int, int>             ii;
const int N = 2002;
int m, d;
char a[N], b[N];
int mod = 1000*1000*1000+7;
int normal(int a){ a%=mod;if(a<0) a = a+mod;return a;}
int add(int a, int b){ return normal(a+b);}
int sub(int a, int b){ return normal(a-b);}

void input(){
    char line[100];
    sscanf(gets(line),"%d %d",&m,&d);
    gets(a);gets(b);
}
big f[N][N][2];
big solve(char *c){
    int n = strlen(c);
    memset(f, 0, sizeof f);
    f[0][0][1] = 1;
    big ans = 0;
    forn(i, n + 1)
      forn(j, m){
          forn(k, 2){
              for(int p = 0;p<= (k? (c[i]-48) : 9);p++){
                  if(p==d && !i&1) continue;
                  if(p!=d && i&1) continue;
                  int ni = i+1;
                  int nj = (j*10+p)%m;
                  int nk = k&&( p == (c[i] - 48 ) );
                  f[ni][nj][nk]=add(f[ni][nj][nk] ,f[i][j][k]);
              }
          }
      }
   forn(k, 2) ans = add(ans, f[n][0][k]);
    return ans;
}
int isgood(char *c){
    int l = strlen(c);
    int remain = 0;
    forn(i, l){
        int p = c[i] - 48;
        if(p!=d&&i&1) return 0;
        if(p==d&&!i&1) return 0;
        remain = (remain*10 + p) %m;///lay du cua no cho m
    }
    return (!remain);
}
int main(){
    input();
    int ans = 0;
    ans = add(ans, solve(b));
    ans = sub(ans, solve(a));
    if(isgood(a)) ans = add(ans, 1);
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int mod = 1000*1000*1000 + 7;
int m,d;
string a,b;
inline int add(int a, int b){ return (a+b<mod)? (a+b): (a+b-mod);}
inline void inc(int &a, int b){      a = add(a,b);            }
#define forn(i,n) for(int i = 0;i<(int)n;i++)

const int N = 2005;

int z[N][N][2];      ///zijk  so cai thoa man voi do dai i , remain j, k : prefix
int solve(string s){
    ///buoc 1: cho tat ca bang 0 tru so 0
    int n = s.size();
    forn(i,n) forn(j,m) forn(k,2) z[i][j][k] = 0;
    z[0][0][1] = 1;

    forn(i,n)
      forn(j,m)
        forn(k,2)
          for(int p = 0;p<=( k? s[i] - '0': 9);p++){
              if((i&1) &&p!=d) continue;           ///
              if(!(i&1) &&p==d) continue;
              if(!i&&!p)       continue;

              int ni = i+1;
              int nj = (j*10 + p)%m;
              int nk = k&&(p ==(int) s[i] -'0');
             inc(z[ni][nj][nk], z[i][j][k]);
          }
    int ans = 0;
    forn(k,2) inc(ans, z[n][0][k]);
    return ans;
}
bool good(string a){
    int remain = 0;
    forn(i,a.size()){
         int p = a[i] - '0';
         if(p==d&& i%2 ==0) return false;
         if(p!=d&& i%2==1) return false;
         remain = (remain*10 + p)%m;
    }
    return (!remain);
}
void check(){
   int ans = 0;
   int x = solve(a);

   int y = solve(b);
   ans = y - x;
   inc(ans, 0);
   if(good(a)) ans = (ans + 1);
   inc(ans, 0);
   cout<<ans<<endl;
}
int main(){
    cin>> m>> d>> a>> b;
    check();
}
///2 6 10 99


#include<bits/stdc++.h>
using namespace std;
const int mod = 1000*1000*1000 + 7;

int m,d;
string a,b;
int add(int a, int b){
    if(a+b<mod) return (a+b);
    else return a+b-mod;
}
void inc(int &a, int b){      a = add(a,b);            }

#define forn(i,n) for(int i = 0;i<(int)n;i++)
 int sub(int &a, int b){
    if(a-b<0) return (a-b+mod);
    else return (a-b);
 }
 void dec(int &a, int b) { a = sub(a,b);}

const int N = 2005;

int z[N][N][2];      ///zijk  so cai thoa man voi do dai i , remain j, k : prefix
int solve(string s){
    ///buoc 1: cho tat ca bang 0 tru so 0
    int n = s.size();
    forn(i,n+1) forn(j,m) forn(k,2) z[i][j][k] = 0;
    z[0][0][1] = 1;

    forn(i,n)
      forn(j,m)
        forn(k,2)
          for(int p = 0;p<=( k?(int) s[i] - '0': 9);p++){
              if((i&1)    &&p!=d) continue;           ///
              if(!(i&1) &&p==d) continue;
              if(!i&&!p)       continue;

              int ni = i+1;
              int nj =(j*10+ p)%m;
              int nk = k&&(p ==(int) (s[i] -'0'));
             inc(z[ni][nj][nk], z[i][j][k]);

          }
    int ans = 0;
    forn(k,2) inc(ans, z[n][0][k]);
    memset(z, 0, sizeof z);
    return ans;
}
bool good(string a){
    int remain = 0;
    forn(i,a.size()){
         int p = int(a[i] - '0');
         if((i&1)&&p!=d) return 0;
         if((!(i&1))&&p==d) return 0;
         remain = (remain*10 + p)%m;
    }
    if(remain==0) return 1;
    else          return 0;
}
void solve(){
  int ans = 0;
  inc(ans, solve(b));
  dec(ans, solve(a));
  inc(ans, good(a));

  cout<<ans<<endl;
}

int main(){
    a.clear();

    cin>> m>> d;
    cin>> a>>b;
    solve();
}
///2 6 10 99
///43 3 587 850
///760 014 418


#include<bits/stdc++.h>
using namespace std;
const int mod = 1000*1000*1000 + 7;
int m,d;
string a,b;
inline int add(int a, int b){ return (a+b)%mod;}
inline void inc(int &a, int b){      a = add(a,b);            }
#define forn(i,n) for(int i = 0;i<(int)n;i++)
inline int sub(int &a, int b){ if(a<b) swap(a,b);
    return (a-b)%mod;}
inline void tru(int &a, int b) { a = sub(a,b);}

const int N = 2005;

int z[N][N][2];      ///zijk  so cai thoa man voi do dai i , remain j, k : prefix
int solve(string s){
    ///buoc 1: cho tat ca bang 0 tru so 0
    int n = s.size();
    forn(i,n+1) forn(j,m) forn(k,2) z[i][j][k] = 0;
    z[0][0][1] = 1;

    forn(i,n)
      forn(j,m)
        forn(k,2)
          for(int p = 0;p<=( k?(int) s[i] - '0': 9);p++){
              if((i&1)    &&p!=d) continue;           ///
              if((!(i&1)) &&p==d) continue;
              if(!i&&!p)       continue;

              int ni = i+1;
              int nj = (long int)(j*10+ p)%m;
              int nk = k&&(p ==(int) s[i] -'0');
             inc(z[ni][nj][nk], z[i][j][k]);
          }
    int ans = 0;
    forn(k,2) inc(ans, z[n][0][k]);
    memset(z, 0, sizeof z);
    return ans;
}
bool good(string a){
    int remain = 0;
    forn(i,a.size()){
         int p = a[i] - '0';
         if(i&1&&p!=d) return 0;
         if((!(i&1))&&p==d) return 0;
         remain = (long int)(remain*10 + p)%m;
    }
    if(remain==0) return 1;
    else          return 0;
}
void check(){
   int ans = 0;
   int x = solve(a);
   int y = solve(b);
   ans = sub(y, x);
  inc(ans, 0);
   if(good(a)) ans++;
    ans = ans%mod;
    if(ans<0) ans = ans + mod;
   cout<<ans<<endl;
}
int main(){
    cin>> m>> d>> a>> b;
    check();
}
///2 6 10 99
///43 3 587 850
///760 014 418


#include<bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0;i<n;i++)
#define for1(i, n) for(int i = 1;i<=n;i++)
const int N = 2005;
const int MOD = 1e9 + 7;
char a[N], b[N];
int m, d;
int f[N][N][2];///pos, remainder, is equal
int add(int u,int v){ return ((u + v)%MOD+MOD)%MOD; }
void inc(int & u,int v){ u = add(u, v); }
int sub(int u,int v){ return ((u - v)%MOD + MOD)%MOD; }

int solve(char * s){
	memset(f, 0, sizeof f);
	int n = strlen(s + 1);
	f[0][0][1] = 1;
	forn(prefix, n){
		forn(rem, m){
			forn(k, 2){
				for(int next_digit = 0;next_digit<=9;next_digit++){
					int nprefix = prefix + 1;
					if(next_digit == 0 && prefix == 0) continue;

					if(k == 1 && next_digit> s[nprefix] - '0') continue;
					if(nprefix%2 == 1 && next_digit == d) continue;
					if(nprefix%2 == 0 && next_digit != d) continue;
					int nrem = (rem * 10 + next_digit)%m;
					int nk = (k && (next_digit == s[nprefix] - '0') );
					inc (f[nprefix][nrem][nk] , f[prefix][rem][k]);

				}
			}
		}
	}
	return f[n][0][1] + f[n][0][0];
}
int main(){
	//freopen("love dp.inp","r",stdin);
   cin >> m >> d;

   scanf("%s", a + 1);
   scanf("%s", b + 1);
   ///subtract a by 1
   int len = strlen(a + 1);
   while(a[len]== '0'){
	  a[len] = '9';
	  len--;
   }
   a[len]--;
   int ans = sub(solve(b) - solve(a));
   cout<< ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0;i<n;i++)
#define for1(i, n) for(int i = 1;i<=n;i++)
const int N = 2005;
const int MOD = 1e9 + 7;
char a[N], b[N];
int m, d;
int f[N][N][2];///pos, remainder, is equal
int add(int u,int v){ return ((u + v)%MOD+MOD)%MOD; }
void inc(int & u,int v){ u = add(u, v); }
int sub(int u,int v){ return ((u - v)%MOD + MOD)%MOD; }

int solve(char * s){
	memset(f, 0, sizeof f);
	int n = strlen(s + 1);
	f[0][0][1] = 1;
	forn(prefix, n){
		forn(rem, m){
			forn(k, 2){
				for(int next_digit = 0;next_digit<=9;next_digit++){
					int nprefix = prefix + 1;
					if(next_digit == 0 && prefix == 0) continue;

					if(k == 1 && next_digit> s[nprefix] - '0') continue;
					if(nprefix%2 == 1 && next_digit == d) continue;
					if(nprefix%2 == 0 && next_digit != d) continue;
					int nrem = (rem * 10 + next_digit)%m;
					int nk = (k && (next_digit == s[nprefix] - '0') );
					inc (f[nprefix][nrem][nk] , f[prefix][rem][k]);

				}
			}
		}
	}
	return f[n][0][1] + f[n][0][0];
}
int main(){
	//freopen("love dp.inp","r",stdin);
   cin >> m >> d;

   scanf("%s", a + 1);
   scanf("%s", b + 1);
   ///subtract a by 1
   int len = strlen(a + 1);
   while(a[len]== '0'){
	  a[len] = '9';
	  len--;
   }
   a[len]--;
   int ans = sub(solve(b), solve(a));
   cout<< ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
const int mod = 1000*1000*1000 + 7;
int m,d;
string a,b;
inline int add(int a, int b){ return (a+b<mod)? (a+b): (a+b-mod);}
inline void inc(int &a, int b){      a = add(a,b);            }
#define forn(i,n) for(int i = 0;i<(int)n;i++)
inline int sub(int a, int b){ if(a<b) swap(a,b);
    return (a-b)<mod? (a-b): (a-b-mod);}
inline void tru(int &a, int b) { a = sub(a,b);}

const int N = 2005;

int z[N][N][2];      ///zijk  so cai thoa man voi do dai i , remain j, k : prefix
int solve(string s){
    ///buoc 1: cho tat ca bang 0 tru so 0
    int n = s.size();
    forn(i,n) forn(j,m) forn(k,2) z[i][j][k] = 0;
    z[0][0][1] = 1;

    forn(i,n)
      forn(j,m)
        forn(k,2)
          for(int p = 0;p<=( k?(int) s[i] - '0': 9);p++){
              if((i&1)    &&p!=d) continue;           ///
              if((!(i&1)) &&p==d) continue;
              if(!i&&!p)       continue;

              int ni = i+1;
              int nj = (j*10 + p)%m;
              int nk = k&&(p ==(int) s[i] -'0');
             inc(z[ni][nj][nk], z[i][j][k]);
          }
    int ans = 0;
    forn(k,2) inc(ans, z[n][0][k]);
    memset(z, 0, sizeof z);
    return ans;
}
bool good(string a){
    int remain = 0;
    forn(i,a.size()){
         int p = a[i] - '0';
         if(i&1&&p!=d) return 0;
         if(!(i&1)&&p==d) return 0;
         remain = (remain*10 + p)%m;
    }
    if(remain==0) return 1;
    else          return 0;
}
void check(){
   int ans = 0;
   int x = solve(a);
   int y = solve(b);
   ans = sub(y, x);
  inc(ans, 0);
   if(good(a)) ans++;

   inc(ans, 0);
   if(ans<0) ans = ans + mod;
   cout<<ans<<endl;
}
int main(){
    cin>> m>> d>> a>> b;
    check();
}
///2 6 10 99
///43 3 587 850


#include<bits/stdc++.h>
using namespace std;
const int mod = 1000*1000*1000 + 7;
int m,d;
string a,b;
inline int add(int a, int b){ return (a+b<mod)? (a+b): (a+b-mod);}
inline void inc(int &a, int b){      a = add(a,b);            }
#define forn(i,n) for(int i = 0;i<(int)n;i++)

const int N = 2005;

int z[N][N][2];      ///zijk  so cai thoa man voi do dai i , remain j, k : prefix
int solve(string s){
    ///buoc 1: cho tat ca bang 0 tru so 0
    int n = s.size();
    forn(i,n) forn(j,m) forn(k,2) z[i][j][k] = 0;
    z[0][0][1] = 1;

    forn(i,n)
      forn(j,m)
        forn(k,2)
          for(int p = 0;p<=( k?(int) s[i] - '0': 9);p++){
              if((i&1)    &&p!=d) continue;           ///
              if((!(i&1)) &&p==d) continue;
              if(!i&&!p)       continue;

              int ni = i+1;
              int nj = (j*10 + p)%m;
              int nk = k&&(p ==(int) s[i] -'0');
             inc(z[ni][nj][nk], z[i][j][k]);
          }
    int ans = 0;
    forn(k,2) inc(ans, z[n][0][k]);
    memset(z, 0, sizeof z);
    return ans;
}
bool good(string a){
    int remain = 0;
    forn(i,a.size()){
         int p = a[i] - '0';
         if(i&1&&p!=d) return 0;
         if(!(i&1)&&p==d) return 0;
         remain = (remain*10 + p)%m;
    }
    if(remain==0) return 1;
    else          return 0;
}
void check(){
   int ans = 0;
   int x = solve(a);
   int y = solve(b);

   ans = y - x;
  inc(ans, 0);
   if(good(a)) ans++;

   inc(ans, 0);
   cout<<ans<<endl;
}
int main(){
    cin>> m>> d>> a>> b;
    check();
}
///2 6 10 99
///43 3 587 850


#include<bits/stdc++.h>
using namespace std;
typedef long long int big;
const big mod = 10000000007;

big m,d;
string a,b;
big add(big a, big b)                 {  return (a+b)%mod;}
void inc(big &a, big b)              {      a = add(a,b);            }

#define forn(i,n) for(big i = 0;i<(big)n;i++)

 big sub(big a, big b){
                                   if(a<b) swap(a,b);
                                   return (a-b)%mod;}
 void tru(big &a, big b) { a = sub(a,b);}

const big N = 2005;

big z[N][N][2];      ///zijk  so cai thoa man voi do dai i , remain j, k : prefix
big solve(string s){
    ///buoc 1: cho tat ca bang 0 tru so 0
    big n = s.size();
    memset(z, 0, sizeof z);
    z[0][0][1] = 1;

    forn(i,n)
      forn(j,m)
        forn(k,2)
          for(big p = 0;p<=( k?(big) s[i] - '0': 9);p++){
              if((i&1)    &&(p!=d)) continue;           ///
              if((!(i&1)) &&p==d) continue;
              if(!i && !p)       continue;

              big ni = i+1;
              big nj = (j*10+ p)%m;
              big nk = (k&&(p ==(big) (s[i] -'0')));
             inc(z[ni][nj][nk], z[i][j][k]);
          }
    big ans = 0;
    forn(k,2) inc(ans, z[n][0][k]);
    return ans;
}
bool good(string a){
    big remain = 0;
    forn(i,a.size()){
         big p = big(a[i] - '0');
         remain = (remain*10 + p)%m;
         if((i&1)&&p!=d) return 0;
         if((!(i&1))&&p==d) return 0;
    }
    return !remain;
}
void check(){
   big ans = 0;
   inc(ans, solve(b));
    tru(ans, solve(a));
    inc(ans, good(a));
    cout << ans << endl;
}
int main(){
    a.clear();

    cin>> m>> d;
    cin>> a>>b;
    check();
}
///2 6 10 99
///43 3 587 850
///760 014 418
///tai sao no lai ra am la sao


#include<bits/stdc++.h>
using namespace std;
#define          mp                make_pair
#define          pb                push_back
typedef long long int big;
#define         x                  first
#define         y                  second
#define         forn(i, n)         for(big i = 0;i<n;i++)
#define         nfor(i, n)         for(big i = n-1;i>=0;i--)

const big N = 2002;
big m, d;
char a[N], b[N];
big mod = 1000*1000*1000+7;
big normal(big a){a = a%mod; if(a<0) a = a+mod;return a;}
void add(big &a, big b){ a = normal(a+b);}
void sub(big &a, big b){ a = normal(a-b);}

void input(){
    char line[100];
    sscanf(gets(line),"%LLd %LLd",&m,&d);
    gets(a);gets(b);
}
big f[N][N][2];
big solve(char *c){
    big n = strlen(c);
    forn(i, n+1) forn(j, m) forn(k, 2) f[i][j][k] = 0;
    f[0][0][1] = 1;
    big ans = 0;
    forn(i, n)
      forn(j, m){
          forn(k, 2){
              for(big p = 0;p<= ( k? (c[i]-48) : 9);p++){
                  if(p==d && !(i&1)) continue;
                  if(p!=d && i&1) continue;
                  if(p==0&&i==0) continue;

                  big ni = i+1;
                  big nj = (j*10+p)%m;
                  big nk = k&&( p == (c[i] - '0' ) );
                  add(f[ni][nj][nk] ,f[i][j][k]);
              }
          }
      }
   forn(k, 2) add(ans, f[n][0][k]);
    return ans;
}
big isgood(char *c){
    big l = strlen(c);
    big remain = 0;
    forn(i, l){
        big p = c[i] - 48;
        if(p!=d&&i&1) return 0;
        if(p==d&&(!(i&1))) return 0;
        remain = (remain*10 + p) %m;///lay du cua no cho m
    }
    return (!remain);
}
int main(){
    input();
    big ans = 0;
    add(ans, solve(b));
    sub(ans, solve(a));

    if(isgood(a)>0) add(ans, 1);

    cout<<ans<<endl;
}
/*
1053 8
1539368
3362621
*/


#include <bits/stdc++.h>
using namespace std;
typedef  long long ll ;
string s;
int d = 6 ;
int m = 2;
const ll mod = 1e9 + 7 ;
bool ismagic(string a){

    int x = 0 ;
    for(int i = 0 ;i < a.length() ; i++){

        if( (i & 1) && a[i]-'0' != d) return 0;
        if( !(i & 1) && a[i]-'0' == d) return 0;
        x = x*10 + (a[i]-'0');
        x %= m ;
    }
    return !x;
}
ll memo[2005][2][2005];

int f(int i =0,int c  =0 , int sum = 0){

    if( i == s.length()) return !(sum%m);

    ll& ret = memo[i][c][sum];
    if ( ret != -1) return ret;

    if(i&1) {

        if(!c && (s[i]-'0') < d) return 0;

        return ret = f(i+1,c,sum*10+d)%mod;

    }
    ll res = 0 ;
    if(!c)
    for(int k = s[i]-'0' ; k >= 0 ; k--){
        if(k == d) continue;
        res += f(i+1, k != (s[i]-'0') , sum*10+k)%mod;
    }
    else
    {
        for(int k = 9 ; k >= 0 ; k--){
            if(k == d) continue;
            res += f(i+1,1,sum*10+k)%mod;
         }
    }
    return ret = res;

}

int main()
{

    string a , b;
    cin >> m >> d ;
    cin >> a >> b;
    s = b;
    memset(memo , -1 , sizeof(memo));
    ll resb = f();
    s = a ;
    memset(memo , -1 , sizeof(memo));
    ll resa = f();

    cout << resb - resa  << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int m ,d ;
bool is(int n){
    if(n % m) return 0;
    int i =1 ;
    while(n){
        int x = n%10;
        if(x == d  && !(i%2)) return 0;
        if(x != d && (i%2)) return 0;
        n/=10;
        i++;
    }
    return true;
}

int main()
{

    int a, b;
    int ans= 0;
    cin >> m >> d >> a >> b;
    for(int i =a ; i <= b ;i++){

        if(is(i)) {
        //    cout << i << endl ;
            ans ++ ;
        }
    }
    cout << ans << endl ;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int m ,d ;
bool is(int n){
    if(n % m) return 0;
    if(n < 10 && n != d) return 1;
    int i =0 ;
    while(n){
        int x = n%10;
        if(x != d  && !(i&1)) return 0;
        n/=10;
        i++;
    }
    return true;
}

int main()
{
    int a, b;
    int ans= 0;
    cin >> m >> d >> a >> b;
    for(int i =a ; i <= b ;i++){

        if(is(i)) ans ++ ;
    }
    cout << ans << endl ;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int m ,d ;
bool is(int n){
    if(n % m) return 0;
    if(n < 10 && n != d) return 1;
    int i =0 ;
    while(n){
        int x = n%10;
        if(x != d  && !(i&1)) return 0;
        n/=10;
        i++;
    }
    return true;
}

int main()
{
    int a, b;
    int ans= 0;
    cin >> m >> d >> a >> b;
    for(int i =a ; i <= b ;i++){

        if(is(i)) ans ++ ;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
string s;
int d = 6 ;
int m = 2;
const ll mod = 1e9 + 7 ;
bool ismagic(string a){

    int x = 0 ;
    for(int i = 0 ;i < a.length() ; i++){

        if( (i & 1) && a[i]-'0' != d) return 0;
        if( !(i & 1) && a[i]-'0' == d) return 0;
        x = x*10 + (a[i]-'0');
        x %= m ;
    }
    return !x;
}
ll memo[2005][2][2005];

int f(int i =0,int c  =0 , int sum = 0){

    if( i == s.length()) return !(sum%m);

    ll& ret = memo[i][c][sum];
    if ( ret != -1) return ret;

    if(i&1) {

        if(!c && (s[i]-'0') < d) return ret = 0;
        //1248

        return ret = f(i+1,c ? 1 : ((s[i]-'0') > d),(sum*10+d)%m)%mod;

    }
    ll res = 0 ;
    if(!c){
    for(int k = s[i]-'0' ; k >= 0 ; k--){
        if(k == d) continue;
        res += f(i+1, k != (s[i]-'0') ,(sum*10+k)%m)%mod;
        res %= mod;
    }
    }
    else
    {
        for(int k = 9 ; k >= 0 ; k--){
            if(k == d) continue;
            res += f(i+1,1,(sum*10+k)%m)%mod;
            res %= mod;
         }
    }
    return ret = res%mod;

}
vector<string> se;
void print(int i =0,int c  =0 , int sum = 0 , string sr = ""){

    if( i == s.length()) {
        if(!(sum%m)) se.push_back(sr);
        return ;

    }

    if(i&1) {

        if(!c && (s[i]-'0') < d) return ;

        print(i+1,c ? 1 :  ( (s[i]-'0') != d ),sum*10+d, sr + ((char)( '0' + d )));
        return ;

    }
    //ll res = 0 ;
    if(!c){
    for(int k = s[i]-'0' ; k >= 0 ; k--){
        if(k == d) continue;
        print(i+1,k != (s[i]-'0'),sum*10+k, sr + ((char)( '0' + k )));
    }
    }
    else
    {
        for(int k = 9 ; k >= 0 ; k--){
            if(k == d) continue;
             print(i+1,1,sum*10+k, sr +((char)( '0' + k )));
         }
    }

}

int main()
{
              //1040201
    /*string a = "1649127", b = "6241670";
    m = 29 ;
    d= 0 ;
    cout << "a" << endl;
    s = a;
    print();
    cout <<se.size()<<endl;
    for(int i =0 ; i < se.size() ; i++)
        cout << se[i] << endl;
    cout << "a" << endl;
    se.clear();
    cout << "b" << endl;
    s = b;

    print();
    cout <<se.size()<<endl;
    for(int i =0 ; i < se.size() ; i++)
        cout << se[i] << endl;
    cout << "b" << endl;*/
    string a , b;
    cin >> m >> d ;
    cin >> a >> b;
    s = b;
    memset(memo , -1 , sizeof(memo));
    ll resb = f();
    s = a ;
    memset(memo , -1 , sizeof(memo));
    ll resa = f();

    cout << ((resb - resa)%mod + mod)%mod+ ismagic(a) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long ll ;
string s;
int d = 6 ;
int m = 2;
const ll mod = 1e9 + 7 ;
bool ismagic(string a){

    int x = 0 ;
    for(int i = 0 ;i < a.length() ; i++){

        if( (i & 1) && a[i]-'0' != d) return 0;
        if( !(i & 1) && a[i]-'0' == d) return 0;
        x = x*10 + (a[i]-'0');
        x %= m ;
    }
    return !x;
}
ll memo[2005][2][2005];

int f(int i =0,int c  =0 , int sum = 0){

    if( i == s.length()) return !(sum%m);

    ll& ret = memo[i][c][sum];
    if ( ret != -1) return ret;

    if(i&1) {

        if(!c && (s[i]-'0') < d) return 0;
        //1248

        return ret = f(i+1,c ? 1 : ((s[i]-'0') != d),(sum*10+d)%m)%mod;

    }
    ll res = 0 ;
    if(!c){
    for(int k = s[i]-'0' ; k >= 0 ; k--){
        if(k == d) continue;
        res += f(i+1, k != (s[i]-'0') ,(sum*10+k)%m)%mod;
    }
    }
    else
    {
        for(int k = 9 ; k >= 0 ; k--){
            if(k == d) continue;
            res += f(i+1,1,(sum*10+k)%m)%mod;
         }
    }
    return ret = res;

}
vector<string> se;
void print(int i =0,int c  =0 , int sum = 0 , string sr = ""){

    if( i == s.length()) {
        if(!(sum%m)) se.push_back(sr);
        return ;

    }

    if(i&1) {

        if(!c && (s[i]-'0') < d) return ;

        print(i+1,c ? 1 :  ( (s[i]-'0') != d ),sum*10+d, sr + ((char)( '0' + d )));
        return ;

    }
    //ll res = 0 ;
    if(!c){
    for(int k = s[i]-'0' ; k >= 0 ; k--){
        if(k == d) continue;
        print(i+1,k != (s[i]-'0'),sum*10+k, sr + ((char)( '0' + k )));
    }
    }
    else
    {
        for(int k = 9 ; k >= 0 ; k--){
            if(k == d) continue;
             print(i+1,1,sum*10+k, sr +((char)( '0' + k )));
         }
    }

}

int main()
{
              //1040201
    /*string a = "1649127", b = "6241670";
    m = 29 ;
    d= 0 ;
    cout << "a" << endl;
    s = a;
    print();
    cout <<se.size()<<endl;
    for(int i =0 ; i < se.size() ; i++)
        cout << se[i] << endl;
    cout << "a" << endl;
    se.clear();
    cout << "b" << endl;
    s = b;

    print();
    cout <<se.size()<<endl;
    for(int i =0 ; i < se.size() ; i++)
        cout << se[i] << endl;
    cout << "b" << endl;*/
    string a , b;
    cin >> m >> d ;
    cin >> a >> b;
    s = b;
    memset(memo , -1 , sizeof(memo));
    ll resb = f();
    s = a ;
    memset(memo , -1 , sizeof(memo));
    ll resa = f();

    cout << resb - resa + ismagic(a) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long ll ;
string s;
int d = 6 ;
int m = 2;
const ll mod = 1e9 + 7 ;
bool ismagic(string a){

    int x = 0 ;
    for(int i = 0 ;i < a.length() ; i++){

        if( (i & 1) && a[i]-'0' != d) return 0;
        if( !(i & 1) && a[i]-'0' == d) return 0;
        x = x*10 + (a[i]-'0');
        x %= m ;
    }
    return !x;
}
ll memo[2005][2][2005];

int f(int i =0,int c  =0 , int sum = 0){

    if( i == s.length()) return !(sum%m);

    ll& ret = memo[i][c][sum];
    if ( ret != -1) return ret;

    if(i&1) {

        if(!c && (s[i]-'0') > d) return 0;

        return ret = f(i+1,c,(sum*10+d)%m)%mod;

    }
    ll res = 0 ;
    if(!c)
    for(int k = s[i]-'0' ; k >= 0 ; k--){
        if(k == d) continue;
        res += f(i+1, k != (s[i]-'0') ,(sum*10+k)%m)%mod;
    }
    else
    {
        for(int k = 9 ; k >= 0 ; k--){
            if(k == d) continue;
            res += f(i+1,1,(sum*10+k)%m)%mod;
         }
    }
    return ret = res;

}
vector<string> se;
void print(int i =0,int c  =0 , int sum = 0 , string sr = ""){

    if( i == s.length()) {
        if(!(sum%m)) se.push_back(sr);
        return ;

    }

    if(i&1) {

        if(!c && (s[i]-'0') > d) return ;

        print(i+1,c,sum*10+d, sr + ((char)( '0' + d )));
        return ;

    }
    //ll res = 0 ;
    if(!c)
    for(int k = s[i]-'0' ; k >= 0 ; k--){
        if(k == d) continue;
        print(i+1,k != (s[i]-'0'),sum*10+k, sr + ((char)( '0' + k )));
    }
    else
    {
        for(int k = 9 ; k >= 0 ; k--){
            if(k == d) continue;
             print(i+1,1,sum*10+k, sr +((char)( '0' + k )));
         }
    }

}

int main()
{

   /* string a = "1649127", b = "6241670";
    m = 29 ;
    d= 0 ;
    cout << "a" << endl;
    s = a;
    print();
    cout <<se.size()<<endl;
    for(int i =0 ; i < se.size() ; i++)
        cout << se[i] << endl;
    cout << "a" << endl;
    se.clear();
    cout << "b" << endl;
    s = b;

    print();
    cout <<se.size()<<endl;
    for(int i =0 ; i < se.size() ; i++)
        cout << se[i] << endl;
    cout << "b" << endl;*/
    string a , b;
    cin >> m >> d ;
    cin >> a >> b;
    s = b;
    memset(memo , -1 , sizeof(memo));
    ll resb = f();
    s = a ;
    memset(memo , -1 , sizeof(memo));
    ll resa = f();

    cout << resb - resa + ismagic(a) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int m ,d ;
bool is(int n){
    if(n % m) return 0;
    int i =0 ;
    int k = log10(n)+1;
    while(n){
        int x = n%10;
        if(x != d  && !((k-i)%2)) return 0;
        if(x == d && ((k-i)%2)) return 0;
        n/=10;
        i++;
    }
    return true;
}

int main()
{

    int a, b;
    int ans= 0;
    cin >> m >> d >> a >> b;
    for(int i =a ; i <= b ;i++){

        if(is(i)) {
         //   cout << i << endl ;
            ans ++ ;
        }
    }
    cout << ans << endl ;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long ll ;
string s;
int d = 6 ;
int m = 2;
const ll mod = 1e9 + 7 ;
bool ismagic(string a){

    int x = 0 ;
    for(int i = 0 ;i < a.length() ; i++){

        if( (i & 1) && a[i]-'0' != d) return 0;
        if( !(i & 1) && a[i]-'0' == d) return 0;
        x = x*10 + (a[i]-'0');
        x %= m ;
    }
    return !x;
}
ll memo[2005][2][2005];

int f(int i =0,int c  =0 , int sum = 0){

    if( i == s.length()) return !(sum%m);

    ll& ret = memo[i][c][sum];
    if ( ret != -1) return ret;

    if(i&1) {

        if(!c && (s[i]-'0') < d) return ret = 0;
        //1248

        return ret = f(i+1,c ? 1 : ((s[i]-'0') != d),(sum*10+d)%m)%mod;

    }
    ll res = 0 ;
    if(!c){
    for(int k = s[i]-'0' ; k >= 0 ; k--){
        if(k == d) continue;
        res += f(i+1, k != (s[i]-'0') ,(sum*10+k)%m)%mod;
        res %= mod;
    }
    }
    else
    {
        for(int k = 9 ; k >= 0 ; k--){
            if(k == d) continue;
            res += f(i+1,1,(sum*10+k)%m)%mod;
            res %= mod;
         }
    }
    return ret = res%mod;

}
vector<string> se;
void print(int i =0,int c  =0 , int sum = 0 , string sr = ""){

    if( i == s.length()) {
        if(!(sum%m)) se.push_back(sr);
        return ;

    }

    if(i&1) {

        if(!c && (s[i]-'0') < d) return ;

        print(i+1,c ? 1 :  ( (s[i]-'0') != d ),sum*10+d, sr + ((char)( '0' + d )));
        return ;

    }
    //ll res = 0 ;
    if(!c){
    for(int k = s[i]-'0' ; k >= 0 ; k--){
        if(k == d) continue;
        print(i+1,k != (s[i]-'0'),sum*10+k, sr + ((char)( '0' + k )));
    }
    }
    else
    {
        for(int k = 9 ; k >= 0 ; k--){
            if(k == d) continue;
             print(i+1,1,sum*10+k, sr +((char)( '0' + k )));
         }
    }

}

int main()
{
              //1040201
    /*string a = "1649127", b = "6241670";
    m = 29 ;
    d= 0 ;
    cout << "a" << endl;
    s = a;
    print();
    cout <<se.size()<<endl;
    for(int i =0 ; i < se.size() ; i++)
        cout << se[i] << endl;
    cout << "a" << endl;
    se.clear();
    cout << "b" << endl;
    s = b;

    print();
    cout <<se.size()<<endl;
    for(int i =0 ; i < se.size() ; i++)
        cout << se[i] << endl;
    cout << "b" << endl;*/
    string a , b;
    cin >> m >> d ;
    cin >> a >> b;
    s = b;
    memset(memo , -1 , sizeof(memo));
    ll resb = f();
    s = a ;
    memset(memo , -1 , sizeof(memo));
    ll resa = f();

    cout << resb - resa + ismagic(a) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long ll ;
string s;
int d = 6 ;
int m = 2;
const ll mod = 1e9 + 7 ;
bool ismagic(string a){

    int x = 0 ;
    for(int i = 0 ;i < a.length() ; i++){

        if( (i & 1) && a[i]-'0' != d) return 0;
        if( !(i & 1) && a[i]-'0' == d) return 0;
        x = x*10 + (a[i]-'0');
        x %= m ;
    }
    return !x;
}
ll memo[2005][2][2005];

int f(int i =0,int c  =0 , int sum = 0){

    if( i == s.length()) return !(sum%m);

    ll& ret = memo[i][c][sum];
    if ( ret != -1) return ret;

    if(i&1) {

        if(!c && (s[i]-'0') < d) return 0;

        return ret = f(i+1,c,sum*10+d)%mod;

    }
    ll res = 0 ;
    if(!c)
    for(int k = s[i]-'0' ; k >= 0 ; k--){
        if(k == d) continue;
        res += f(i+1, k != (s[i]-'0') , sum*10+k)%mod;
    }
    else
    {
        for(int k = 9 ; k >= 0 ; k--){
            if(k == d) continue;
            res += f(i+1,1,sum*10+k)%mod;
         }
    }
    return ret = res;

}

int main()
{

    string a , b;
    cin >> m >> d ;
    cin >> a >> b;
    s = b;
    memset(memo , -1 , sizeof(memo));
    ll resb = f();
    s = a ;
    memset(memo , -1 , sizeof(memo));
    ll resa = f();

    cout << resb - resa + ismagic(a) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int m ,d ;
bool is(int n){
    if(n % m) return 0;
    if(n < 10 && n != d) return 1;
    int i =0 ;
    while(n){
        int x = n%10;
        if(x != d  && !(i&1)) return 0;
        if(x == d && (i&1)) return 0;
        n/=10;
        i++;
    }
    return true;
}

int main()
{
    int a, b;
    int ans= 0;
    cin >> m >> d >> a >> b;
    for(int i =a ; i <= b ;i++){

        if(is(i)) {
          //  cout << i << endl ;
            ans ++ ;
        }
    }
    cout << ans << endl ;
    return 0;
}


#include <bits/stdc++.h>

#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); ––x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef vector <PII> VPII;

const LL MOD = 1e9 + 7;
const int MAXN = 2e3 + 9;

char s[MAXN];
char s2[MAXN];
LL dp[MAXN][MAXN];
LL potega[MAXN];
LL d;
LL m;

string minuss(string str)
{
    int n = SIZE(str);
    int reszta = -1;

    for(int i = n - 1; i >= 0; i--)
      {
         if(reszta + str[i] - '0' >= 0)
           {
              str[i] += reszta;
              break;
           }

         if(reszta + str[i] - '0' < 0)
           {
              str[i] = str[i] + 10 + reszta;
              reszta = -1;
           }
      }

    string strr;
    bool czy = false;

    REP(i, n)
      {
          if(str[i] != '0')
            czy = true;

          if(czy)
            strr += str[i];
      }

    return strr;
}

LL licz(string &str, int n)
{
    int pocz = SIZE(str) - n;
    LL ans = 0;
    LL reszta = 0;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 1)
            {
                if(str[i] - '0' < d)
                  return 0;

                reszta += d * potega[n - (i - pocz) - 1];
                reszta %= m;
            }
      }

    LL tmp = 0;
    bool czy = false;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 0)
            {
                if(str[i] - '0' == d)
                  str[i]--;

                REP(j, str[i] - '0')
                  {
                      if(j == d)
                        continue;

                      if(!czy)
                        {
                            if(j == 0)
                              continue;
                        }

                      tmp = reszta;
                      tmp += j * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(i < SIZE(str) - 2)
                        ans += dp[n - (i - pocz) - 3][(m - tmp) % m];

                      else if(tmp == 0)
                        ans++;

                      ans %= MOD;
                      //cerr<<"CYFRA "<<j<<" "<<ans<<" "<<tmp<<" "<<i<<" "<<SIZE(str) - 2<<" "<<n - (i - pocz) - 3<<endl;
                  }

                if(str[i] - '0' + 1 == d)
                  str[i]++;

                if(str[i] != '0')
                  czy = true;

                if(str[i] - '0' == d)
                  str[i]--;

                if((i >= SIZE(str) - 2) && (czy))
                  {
                      tmp = reszta;
                      tmp += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(tmp == 0)
                        ans++;

                      ans %= MOD;
                  }

                reszta += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                reszta %= m;

                if(str[i] - '0' + 1 == d)
                  str[i]++;
            }

          else if(d != 0)
            czy = true;
      }

    return ans;
}

LL oblicz(string &str)
{
    int n = SIZE(str);
    LL ans = 0;

    FOR(i, 1, n)
      ans += licz(str, i), ans %= MOD;//, cerr<<"NUMEr "<<i<<" "<<ans<<endl;

    return ans;
}

int main()
{
    int dl = 0, dl2 = 0;

    cin>>m>>d;

    scanf("%s", s);
    scanf("%s", s2);

    while(s[dl]) dl++;
    while(s2[dl2]) dl2++;

    int n = max(dl, dl2) + 2;

    potega[0] = 1 % m;

    FOR(i, 1, n)
      potega[i] = potega[i - 1] * 10, potega[i] %= m;

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[0][i % m]++;
      }

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[1][(i * 10) % m]++;
      }

    LL pot = 10;
    LL tmp = 0;

    FOR(i, 2, n)
      {
          pot *= 10;
          pot %= m;

          REP(j, 10)
            {
               if(j == d)
                 continue;

               REP(k, m)
                 {
                     tmp = (pot * j) % m;

                     if(tmp <= k)
                       {
                           dp[i][k] += dp[i - 2][k - tmp];
                       }

                     else
                       {
                           dp[i][k] += dp[i - 2][m - tmp + k];
                       }

                     dp[i][k] %= MOD;
                 }
            }
      }

    string st = minuss(s);
    string st2 = s2;

   // cerr<<st<<endl;
   // cerr<<oblicz(st2)<<endl;

    cout<<(oblicz(st2) - oblicz(st) + MOD) % MOD<<endl;

    return 0;
}


#include <bits/stdc++.h>

#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef vector <PII> VPII;

const LL MOD = 1e9 + 7;
const int MAXN = 2e3 + 9;

char s[MAXN];
char s2[MAXN];
LL dp[MAXN][MAXN];
LL potega[MAXN];
LL d;
LL m;
int glos;

string minuss(string str)
{
    int n = SIZE(str);
    int reszta = -1;

    for(int i = n - 1; i >= 0; i--)
      {
         if(reszta + str[i] - '0' >= 0)
           {
              str[i] += reszta;
              break;
           }

         if(reszta + str[i] - '0' < 0)
           {
              str[i] = str[i] + 10 + reszta;
              reszta = -1;
           }
      }

    string strr;
    bool czy = false;

    REP(i, n)
      {
          if(str[i] != '0')
            czy = true;

          if(czy)
            strr += str[i];
      }

    if(SIZE(strr) == 0)
      strr = "0";

    return strr;
}

LL licz(string &str, int n)
{
    if(str == "0")
      return 0;

    int pocz = SIZE(str) - n;
    LL ans = 0;
    LL reszta = 0;
    int ost = MAXN + 1000;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 1)
            {
                if(str[i] - '0' < d)
                  {
                      if(ost == MAXN + 1000)
                        ost = i - 1;
                  }

                reszta += d * potega[n - (i - pocz) - 1];
                reszta %= m;
            }
      }

    LL tmp = 0;
    bool czy = false;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 0)
            {
                if(str[i] - '0' == d)
                  {
                      if(!czy)
                        {
                            czy = true;
                            ost = MAXN + 1000;

                            FOR(j, i + 1, n)
                              str[j] = '9';
                        }

                      str[i]--;
                  }

                REP(j, str[i] - '0')
                  {
                      if(j == d)
                        continue;

                      if(i == pocz)
                        {
                            if(j == 0)
                              continue;
                        }

                      tmp = reszta;
                      tmp += j * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(i < SIZE(str) - 2)
                        ans += dp[n - (i - pocz) - 3][(m - tmp) % m];

                      else if(tmp == 0)
                        ans++;

                      ans %= MOD;
                      //cerr<<"CYFRA "<<j<<" "<<ans<<" "<<tmp<<"RE "<<reszta<<" "<<i<<" "<<SIZE(str) - 2<<" "<<n<<endl;
                  }

                if(ost == i)
                  break;

                if(i >= SIZE(str) - 2)
                  {
                      tmp = reszta;
                      tmp += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(tmp == 0)
                        ans++;

                      ans %= MOD;
                  }

                reszta += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                reszta %= m;

                if(str[i] - '0' + 1 == d)
                  str[i]++;
            }

          else if((!czy) && (str[i] - '0' > d))
            {//cerr<<"Co"<<endl;
                czy = true;
                ost = MAXN + 1000;

                REP(j, n)
                  str[j] = '9';
            }
      }

    return ans;
}

LL oblicz(string &str)
{
    if(SIZE(str) != glos)
      return 0;

   // cerr<<"OBLICZ "<<str<<endl;
    int n = SIZE(str);
    LL ans = 0;

    ans = licz(str, n);

   // FORD(i, n, 1)
    //  ans += licz(str, i), ans %= MOD;//, cerr<<"NUMEr "<<i<<" "<<ans<<endl;

    return ans;
}

int main()
{
    int dl = 0, dl2 = 0;

    cin>>m>>d;

    scanf("%s", s);
    scanf("%s", s2);

    while(s[dl]) dl++;
    while(s2[dl2]) dl2++;

    int n = max(dl, dl2) + 2;

    potega[0] = 1 % m;

    FOR(i, 1, n)
      potega[i] = potega[i - 1] * 10, potega[i] %= m;

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[0][i % m]++;
      }

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[1][(i * 10) % m]++;
      }

    LL pot = 10;
    LL tmp = 0;

    FOR(i, 2, n)
      {
          pot *= 10;
          pot %= m;

          REP(j, 10)
            {
               if(j == d)
                 continue;

               REP(k, m)
                 {
                     tmp = (pot * j) % m;

                     if(tmp <= k)
                       {
                           dp[i][k] += dp[i - 2][k - tmp];
                       }

                     else
                       {
                           dp[i][k] += dp[i - 2][m - tmp + k];
                       }

                     dp[i][k] %= MOD;
                 }
            }
      }

    string st = minuss(s);
    string st2 = s2;

    glos = SIZE(st2);

    //cerr<<"JEDEN "<<oblicz(st2)<<" "<<oblicz(st)<<endl;

    cout<<(oblicz(st2) - oblicz(st) + MOD) % MOD<<endl;

    return 0;
}


#include <bits/stdc++.h>

#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef vector <PII> VPII;

const LL MOD = 1e9 + 7;
const int MAXN = 2e3 + 9;

char s[MAXN];
char s2[MAXN];
LL dp[MAXN][MAXN];
LL potega[MAXN];
LL d;
LL m;
int glos;

string minuss(string str)
{
    int n = SIZE(str);
    int reszta = -1;

    for(int i = n - 1; i >= 0; i--)
      {
         if(reszta + str[i] - '0' >= 0)
           {
              str[i] += reszta;
              break;
           }

         if(reszta + str[i] - '0' < 0)
           {
              str[i] = str[i] + 10 + reszta;
              reszta = -1;
           }
      }

    string strr;
    bool czy = false;

    REP(i, n)
      {
          if(str[i] != '0')
            czy = true;

          if(czy)
            strr += str[i];
      }

    if(SIZE(strr) == 0)
      strr = "0";

    return strr;
}

LL licz(string &str, int n)
{
    int pocz = SIZE(str) - n;
    LL ans = 0;
    LL reszta = 0;
    int ost = MAXN + 1000;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 1)
            {
                if(str[i] - '0' < d)
                  {
                      if(ost == MAXN + 1000)
                        ost = i - 1;
                  }

                reszta += d * potega[n - (i - pocz) - 1];
                reszta %= m;
            }
      }

    LL tmp = 0;
    bool czy = false;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 0)
            {
                if(str[i] - '0' == d)
                  str[i]--;

                REP(j, str[i] - '0')
                  {
                      if(j == d)
                        continue;

                      if(i == pocz)
                        {
                            if(j == 0)
                              continue;
                        }

                      tmp = reszta;
                      tmp += j * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(i < SIZE(str) - 2)
                        ans += dp[n - (i - pocz) - 3][(m - tmp) % m];

                      else if(tmp == 0)
                        ans++;

                      ans %= MOD;
                    //  cerr<<"CYFRA "<<j<<" "<<ans<<" "<<tmp<<"RE "<<reszta<<" "<<i<<" "<<SIZE(str) - 2<<" "<<n<<endl;
                  }

                if(ost == i)
                  break;

                if(i >= SIZE(str) - 2)
                  {
                      tmp = reszta;
                      tmp += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(tmp == 0)
                        ans++;

                      ans %= MOD;
                  }

                reszta += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                reszta %= m;

                if(str[i] - '0' + 1 == d)
                  str[i]++;
            }

          else if((!czy) && (str[i] - '0' > d))
            {//cerr<<"Co"<<endl;
                czy = true;

                REP(j, n)
                  str[j] = '9';
            }
      }

    return ans;
}

LL oblicz(string &str)
{
    if(SIZE(str) != glos)
      return 0;

    //cerr<<"OBLICZ "<<str<<endl;
    int n = SIZE(str);
    LL ans = 0;

    ans = licz(str, n);

   // FORD(i, n, 1)
    //  ans += licz(str, i), ans %= MOD;//, cerr<<"NUMEr "<<i<<" "<<ans<<endl;

    return ans;
}

int main()
{
    int dl = 0, dl2 = 0;

    cin>>m>>d;

    scanf("%s", s);
    scanf("%s", s2);

    while(s[dl]) dl++;
    while(s2[dl2]) dl2++;

    int n = max(dl, dl2) + 2;

    potega[0] = 1 % m;

    FOR(i, 1, n)
      potega[i] = potega[i - 1] * 10, potega[i] %= m;

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[0][i % m]++;
      }

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[1][(i * 10) % m]++;
      }

    LL pot = 10;
    LL tmp = 0;

    FOR(i, 2, n)
      {
          pot *= 10;
          pot %= m;

          REP(j, 10)
            {
               if(j == d)
                 continue;

               REP(k, m)
                 {
                     tmp = (pot * j) % m;

                     if(tmp <= k)
                       {
                           dp[i][k] += dp[i - 2][k - tmp];
                       }

                     else
                       {
                           dp[i][k] += dp[i - 2][m - tmp + k];
                       }

                     dp[i][k] %= MOD;
                 }
            }
      }

    string st = minuss(s);
    string st2 = s2;

    glos = SIZE(st2);

   // cerr<<"JEDEN "<<oblicz(st2)<<" "<<oblicz(st)<<endl;

    cout<<(oblicz(st2) - oblicz(st) + MOD) % MOD<<endl;

    return 0;
}


#include <bits/stdc++.h>

#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef vector <PII> VPII;

const LL MOD = 1e9 + 7;
const int MAXN = 2e3 + 9;

char s[MAXN];
char s2[MAXN];
LL dp[MAXN][MAXN];
LL potega[MAXN];
LL d;
LL m;
int glos;

string minuss(string str)
{
    int n = SIZE(str);
    int reszta = -1;

    for(int i = n - 1; i >= 0; i--)
      {
         if(reszta + str[i] - '0' >= 0)
           {
              str[i] += reszta;
              break;
           }

         if(reszta + str[i] - '0' < 0)
           {
              str[i] = str[i] + 10 + reszta;
              reszta = -1;
           }
      }

    string strr;
    bool czy = false;

    REP(i, n)
      {
          if(str[i] != '0')
            czy = true;

          if(czy)
            strr += str[i];
      }

    if(SIZE(strr) == 0)
      strr = "0";

    return strr;
}

LL licz(string &str, int n)
{
    int pocz = SIZE(str) - n;
    LL ans = 0;
    LL reszta = 0;
    int ost = MAXN + 1000;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 1)
            {
                if(str[i] - '0' < d)
                  {
                      if(ost == MAXN + 1000)
                        ost = i - 1;
                  }

                reszta += d * potega[n - (i - pocz) - 1];
                reszta %= m;
            }
      }

    LL tmp = 0;
    bool czy = false;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 0)
            {
                if(str[i] - '0' == d)
                  str[i]--;

                REP(j, str[i] - '0')
                  {
                      if(j == d)
                        continue;

                      if(i == pocz)
                        {
                            if(j == 0)
                              continue;
                        }

                      tmp = reszta;
                      tmp += j * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(i < SIZE(str) - 2)
                        ans += dp[n - (i - pocz) - 3][(m - tmp) % m];

                      else if(tmp == 0)
                        ans++;

                      ans %= MOD;
                    //  cerr<<"CYFRA "<<j<<" "<<ans<<" "<<tmp<<"RE "<<reszta<<" "<<i<<" "<<SIZE(str) - 2<<" "<<n<<endl;
                  }

                if(ost == i)
                  break;

                if(i >= SIZE(str) - 2)
                  {
                      tmp = reszta;
                      tmp += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(tmp == 0)
                        ans++;

                      ans %= MOD;
                  }

                reszta += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                reszta %= m;

                if(str[i] - '0' + 1 == d)
                  str[i]++;
            }

          else if((!czy) && (str[i] - '0' > d))
            {//cerr<<"Co"<<endl;
                czy = true;
                ost = MAXN + 1000;

                REP(j, n)
                  str[j] = '9';
            }
      }

    return ans;
}

LL oblicz(string &str)
{
    if(SIZE(str) != glos)
      return 0;

    //cerr<<"OBLICZ "<<str<<endl;
    int n = SIZE(str);
    LL ans = 0;

    ans = licz(str, n);

   // FORD(i, n, 1)
    //  ans += licz(str, i), ans %= MOD;//, cerr<<"NUMEr "<<i<<" "<<ans<<endl;

    return ans;
}

int main()
{
    int dl = 0, dl2 = 0;

    cin>>m>>d;

    scanf("%s", s);
    scanf("%s", s2);

    while(s[dl]) dl++;
    while(s2[dl2]) dl2++;

    int n = max(dl, dl2) + 2;

    potega[0] = 1 % m;

    FOR(i, 1, n)
      potega[i] = potega[i - 1] * 10, potega[i] %= m;

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[0][i % m]++;
      }

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[1][(i * 10) % m]++;
      }

    LL pot = 10;
    LL tmp = 0;

    FOR(i, 2, n)
      {
          pot *= 10;
          pot %= m;

          REP(j, 10)
            {
               if(j == d)
                 continue;

               REP(k, m)
                 {
                     tmp = (pot * j) % m;

                     if(tmp <= k)
                       {
                           dp[i][k] += dp[i - 2][k - tmp];
                       }

                     else
                       {
                           dp[i][k] += dp[i - 2][m - tmp + k];
                       }

                     dp[i][k] %= MOD;
                 }
            }
      }

    string st = minuss(s);
    string st2 = s2;

    glos = SIZE(st2);

   // cerr<<"JEDEN "<<oblicz(st2)<<" "<<oblicz(st)<<endl;

    cout<<(oblicz(st2) - oblicz(st) + MOD) % MOD<<endl;

    return 0;
}


#include <bits/stdc++.h>

#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef vector <PII> VPII;

const LL MOD = 1e9 + 7;
const int MAXN = 2e3 + 9;

char s[MAXN];
char s2[MAXN];
LL dp[MAXN][MAXN];
LL potega[MAXN];
LL d;
LL m;
int glos;

string minuss(string str)
{
    int n = SIZE(str);
    int reszta = -1;

    for(int i = n - 1; i >= 0; i--)
      {
         if(reszta + str[i] - '0' >= 0)
           {
              str[i] += reszta;
              break;
           }

         if(reszta + str[i] - '0' < 0)
           {
              str[i] = str[i] + 10 + reszta;
              reszta = -1;
           }
      }

    string strr;
    bool czy = false;

    REP(i, n)
      {
          if(str[i] != '0')
            czy = true;

          if(czy)
            strr += str[i];
      }

    if(SIZE(strr) == 0)
      strr = "0";

    return strr;
}

LL licz(string &str, int n)
{
    if(str == "0")
      return 0;

    int pocz = SIZE(str) - n;
    LL ans = 0;
    LL reszta = 0;
    int ost = MAXN + 1000;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 1)
            {
                if(str[i] - '0' < d)
                  {
                      if(ost == MAXN + 1000)
                        ost = i - 1;
                  }

                reszta += d * potega[n - (i - pocz) - 1];
                reszta %= m;
            }
      }

    LL tmp = 0;
    bool czy = false;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 0)
            {
                if(str[i] - '0' == d)
                  {
                      if((i == pocz) && (d == 1))
                        return 0;

                      if(!czy)
                        {
                            czy = true;
                            ost = MAXN + 1000;

                            FOR(j, i + 1, n)
                              str[j] = '9';
                        }

                      str[i]--;
                  }

                REP(j, str[i] - '0')
                  {
                      if(j == d)
                        continue;

                      if(i == pocz)
                        {
                            if(j == 0)
                              continue;
                        }

                      tmp = reszta;
                      tmp += j * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(i < SIZE(str) - 2)
                        ans += dp[n - (i - pocz) - 3][(m - tmp) % m];

                      else if(tmp == 0)
                        ans++;

                      ans %= MOD;
                     // cerr<<"CYFRA "<<j<<" "<<ans<<" "<<tmp<<"RE "<<reszta<<" "<<i<<" "<<SIZE(str) - 2<<" "<<n<<endl;
                  }

                if(ost == i)
                  break;

                if(i >= SIZE(str) - 2)
                  {
                      tmp = reszta;
                      tmp += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(tmp == 0)
                        ans++;

                      ans %= MOD;
                  }

                reszta += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                reszta %= m;

                if(str[i] - '0' + 1 == d)
                  str[i]++;
            }

          else if((!czy) && (str[i] - '0' > d))
            {//cerr<<"Co"<<endl;
                czy = true;
                ost = MAXN + 1000;

                REP(j, n)
                  str[j] = '9';
            }
      }

    return ans;
}

LL oblicz(string &str)
{
    if(SIZE(str) != glos)
      return 0;

   // cerr<<"OBLICZ "<<str<<endl;
    int n = SIZE(str);
    LL ans = 0;

    ans = licz(str, n);

   // FORD(i, n, 1)
    //  ans += licz(str, i), ans %= MOD;//, cerr<<"NUMEr "<<i<<" "<<ans<<endl;

    return ans;
}

int main()
{
    int dl = 0, dl2 = 0;

    cin>>m>>d;

    scanf("%s", s);
    scanf("%s", s2);

    while(s[dl]) dl++;
    while(s2[dl2]) dl2++;

    int n = max(dl, dl2) + 2;

    potega[0] = 1 % m;

    FOR(i, 1, n)
      potega[i] = potega[i - 1] * 10, potega[i] %= m;

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[0][i % m]++;
      }

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[1][(i * 10) % m]++;
      }

    LL pot = 10;
    LL tmp = 0;

    FOR(i, 2, n)
      {
          pot *= 10;
          pot %= m;

          REP(j, 10)
            {
               if(j == d)
                 continue;

               REP(k, m)
                 {
                     tmp = (pot * j) % m;

                     if(tmp <= k)
                       {
                           dp[i][k] += dp[i - 2][k - tmp];
                       }

                     else
                       {
                           dp[i][k] += dp[i - 2][m - tmp + k];
                       }

                     dp[i][k] %= MOD;
                 }
            }
      }

    string st = minuss(s);
    string st2 = s2;

    glos = SIZE(st2);

   // cerr<<"JEDEN "<<oblicz(st2)<<" "<<oblicz(st)<<endl;

    cout<<(oblicz(st2) - oblicz(st) + MOD) % MOD<<endl;

    return 0;
}


#include <bits/stdc++.h>

#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef vector <PII> VPII;

const LL MOD = 1e9 + 7;
const int MAXN = 2e3 + 9;

char s[MAXN];
char s2[MAXN];
LL dp[MAXN][MAXN];
LL potega[MAXN];
LL d;
LL m;

string minuss(string str)
{
    int n = SIZE(str);
    int reszta = -1;

    for(int i = n - 1; i >= 0; i--)
      {
         if(reszta + str[i] - '0' >= 0)
           {
              str[i] += reszta;
              break;
           }

         if(reszta + str[i] - '0' < 0)
           {
              str[i] = str[i] + 10 + reszta;
              reszta = -1;
           }
      }

    string strr;
    bool czy = false;

    REP(i, n)
      {
          if(str[i] != '0')
            czy = true;

          if(czy)
            strr += str[i];
      }

    if(SIZE(strr) == 0)
      strr = "0";

    return strr;
}

LL licz(string &str, int n)
{
    int pocz = SIZE(str) - n;
    LL ans = 0;
    LL reszta = 0;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 1)
            {
                if(str[i] - '0' < d)
                  return 0;

                reszta += d * potega[n - (i - pocz) - 1];
                reszta %= m;
            }
      }

    LL tmp = 0;
    bool czy = false;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 0)
            {
                if(str[i] - '0' == d)
                  str[i]--;

                REP(j, str[i] - '0')
                  {
                      if(j == d)
                        continue;

                      if(!czy)
                        {
                            if(j == 0)
                              continue;
                        }

                      tmp = reszta;
                      tmp += j * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(i < SIZE(str) - 2)
                        ans += dp[n - (i - pocz) - 3][(m - tmp) % m];

                      else if(tmp == 0)
                        ans++;

                      ans %= MOD;
                   //   cerr<<"CYFRA "<<j<<" "<<ans<<" "<<tmp<<" "<<i<<" "<<SIZE(str) - 2<<" "<<n - (i - pocz) - 3<<endl;
                  }

                if(str[i] - '0' + 1 == d)
                  str[i]++;

                if(str[i] != '0')
                  czy = true;

                if(str[i] - '0' == d)
                  str[i]--;

                if((i >= SIZE(str) - 2) && (czy))
                  {
                      tmp = reszta;
                      tmp += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(tmp == 0)
                        ans++;

                      ans %= MOD;
                  }

                reszta += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                reszta %= m;

                if(str[i] - '0' + 1 == d)
                  str[i]++;
            }

          else if(d != 0)
            czy = true;
      }

    if(n == SIZE(str))
      {
          REP(i, n)
            str[i] = '9';
      }

    return ans;
}

LL oblicz(string &str)
{
    int n = SIZE(str);
    LL ans = 0;

    FORD(i, n, 1)
      ans += licz(str, i), ans %= MOD;//, cerr<<"NUMEr "<<i<<" "<<ans<<endl;

    return ans;
}

int main()
{
    int dl = 0, dl2 = 0;

    cin>>m>>d;

    scanf("%s", s);
    scanf("%s", s2);

    while(s[dl]) dl++;
    while(s2[dl2]) dl2++;

    int n = max(dl, dl2) + 2;

    potega[0] = 1 % m;

    FOR(i, 1, n)
      potega[i] = potega[i - 1] * 10, potega[i] %= m;

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[0][i % m]++;
      }

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[1][(i * 10) % m]++;
      }

    LL pot = 10;
    LL tmp = 0;

    FOR(i, 2, n)
      {
          pot *= 10;
          pot %= m;

          REP(j, 10)
            {
               if(j == d)
                 continue;

               REP(k, m)
                 {
                     tmp = (pot * j) % m;

                     if(tmp <= k)
                       {
                           dp[i][k] += dp[i - 2][k - tmp];
                       }

                     else
                       {
                           dp[i][k] += dp[i - 2][m - tmp + k];
                       }

                     dp[i][k] %= MOD;
                 }
            }
      }

    string st = minuss(s);
    string st2 = s2;

   // cerr<<st<<endl;
   // cerr<<"JEDEN "<<oblicz(st2)<<" "<<oblicz(st)<<endl;

    cout<<(oblicz(st2) - oblicz(st) + MOD) % MOD<<endl;

    return 0;
}


#include <bits/stdc++.h>

#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef vector <PII> VPII;

const LL MOD = 1e9 + 7;
const int MAXN = 2e3 + 9;

char s[MAXN];
char s2[MAXN];
LL dp[MAXN][MAXN];
LL potega[MAXN];
LL d;
LL m;
int glos;

string minuss(string str)
{
    int n = SIZE(str);
    int reszta = -1;

    for(int i = n - 1; i >= 0; i--)
      {
         if(reszta + str[i] - '0' >= 0)
           {
              str[i] += reszta;
              break;
           }

         if(reszta + str[i] - '0' < 0)
           {
              str[i] = str[i] + 10 + reszta;
              reszta = -1;
           }
      }

    string strr;
    bool czy = false;

    REP(i, n)
      {
          if(str[i] != '0')
            czy = true;

          if(czy)
            strr += str[i];
      }

    if(SIZE(strr) == 0)
      strr = "0";

    return strr;
}

LL licz(string &str, int n)
{
    int pocz = SIZE(str) - n;
    LL ans = 0;
    LL reszta = 0;
    int ost = MAXN + 1000;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 1)
            {
                if(str[i] - '0' < d)
                  {
                      if(ost == MAXN + 1000)
                        ost = i - 1;
                  }

                reszta += d * potega[n - (i - pocz) - 1];
                reszta %= m;
            }
      }

    LL tmp = 0;
    bool czy = false;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 0)
            {
                if(str[i] - '0' == d)
                  str[i]--;

                REP(j, str[i] - '0')
                  {
                      if(j == d)
                        continue;

                      if(!czy)
                        {
                            if(j == 0)
                              continue;
                        }

                      tmp = reszta;
                      tmp += j * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(i < SIZE(str) - 2)
                        ans += dp[n - (i - pocz) - 3][(m - tmp) % m];

                      else if(tmp == 0)
                        ans++;

                      ans %= MOD;
                    //  cerr<<"CYFRA "<<j<<" "<<ans<<" "<<tmp<<"RE "<<reszta<<" "<<i<<" "<<SIZE(str) - 2<<" "<<n<<endl;
                  }

                if(ost == i)
                  break;

                if(str[i] - '0' + 1 == d)
                  str[i]++;

                if(str[i] != '0')
                  czy = true;

                if(str[i] - '0' == d)
                  str[i]--;

                if((i >= SIZE(str) - 2) && (czy))
                  {
                      tmp = reszta;
                      tmp += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(tmp == 0)
                        ans++;

                      ans %= MOD;
                  }

                reszta += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                reszta %= m;

                if(str[i] - '0' + 1 == d)
                  str[i]++;
            }

          else if(d != 0)
            czy = true;
      }

    return ans;
}

LL oblicz(string &str)
{
    if(SIZE(str) != glos)
      return 0;

    //cerr<<"OBLICZ "<<str<<endl;
    int n = SIZE(str);
    LL ans = 0;

    ans = licz(str, n);

   // FORD(i, n, 1)
    //  ans += licz(str, i), ans %= MOD;//, cerr<<"NUMEr "<<i<<" "<<ans<<endl;

    return ans;
}

int main()
{
    int dl = 0, dl2 = 0;

    cin>>m>>d;

    scanf("%s", s);
    scanf("%s", s2);

    while(s[dl]) dl++;
    while(s2[dl2]) dl2++;

    int n = max(dl, dl2) + 2;

    potega[0] = 1 % m;

    FOR(i, 1, n)
      potega[i] = potega[i - 1] * 10, potega[i] %= m;

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[0][i % m]++;
      }

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[1][(i * 10) % m]++;
      }

    LL pot = 10;
    LL tmp = 0;

    FOR(i, 2, n)
      {
          pot *= 10;
          pot %= m;

          REP(j, 10)
            {
               if(j == d)
                 continue;

               REP(k, m)
                 {
                     tmp = (pot * j) % m;

                     if(tmp <= k)
                       {
                           dp[i][k] += dp[i - 2][k - tmp];
                       }

                     else
                       {
                           dp[i][k] += dp[i - 2][m - tmp + k];
                       }

                     dp[i][k] %= MOD;
                 }
            }
      }

    string st = minuss(s);
    string st2 = s2;

    glos = SIZE(st2);

    //cerr<<"JEDEN "<<oblicz(st2)<<" "<<oblicz(st)<<endl;

    cout<<(oblicz(st2) - oblicz(st) + MOD) % MOD<<endl;

    return 0;
}


#include <bits/stdc++.h>

#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef vector <PII> VPII;

const LL MOD = 1e9 + 7;
const int MAXN = 2e3 + 9;

char s[MAXN];
char s2[MAXN];
LL dp[MAXN][MAXN];
LL potega[MAXN];
LL d;
LL m;

string minuss(string str)
{
    int n = SIZE(str);
    int reszta = -1;

    for(int i = n - 1; i >= 0; i--)
      {
         if(reszta + str[i] - '0' >= 0)
           {
              str[i] += reszta;
              break;
           }

         if(reszta + str[i] - '0' < 0)
           {
              str[i] = str[i] + 10 + reszta;
              reszta = -1;
           }
      }

    string strr;
    bool czy = false;

    REP(i, n)
      {
          if(str[i] != '0')
            czy = true;

          if(czy)
            strr += str[i];
      }

    if(SIZE(strr) == 0)
      strr = "0";

    return strr;
}

LL licz(string &str, int n)
{
    int pocz = SIZE(str) - n;
    LL ans = 0;
    LL reszta = 0;

    bool czy = false;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 1)
            {
                if((str[i] - '0' < d) && (!czy))
                  {
                      if(n == SIZE(str))
                      {
                          REP(i, n)
                            str[i] = '9';
                      }

                      return 0;
                  }

                if(str[i] - '0' > d)
                  czy = true;

                reszta += d * potega[n - (i - pocz) - 1];
                reszta %= m;
            }

          else
            {
                if(i == 0)
                  if(str[i] > '1')
                    czy = true;

                if(i > 0)
                  if(str[i] > '0')
                    czy = true;
            }
      }

    LL tmp = 0;
    czy = false;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 0)
            {
                if(str[i] - '0' == d)
                  str[i]--;

                REP(j, str[i] - '0')
                  {
                      if(j == d)
                        continue;

                      if(!czy)
                        {
                            if(j == 0)
                              continue;
                        }

                      tmp = reszta;
                      tmp += j * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(i < SIZE(str) - 2)
                        ans += dp[n - (i - pocz) - 3][(m - tmp) % m];

                      else if(tmp == 0)
                        ans++;

                      ans %= MOD;
                     // cerr<<"CYFRA "<<j<<" "<<ans<<" "<<tmp<<" "<<i<<" "<<SIZE(str) - 2<<" "<<n - (i - pocz) - 3<<endl;
                  }

                if(str[i] - '0' + 1 == d)
                  str[i]++;

                if(str[i] != '0')
                  czy = true;

                if(str[i] - '0' == d)
                  str[i]--;

                if((i >= SIZE(str) - 2) && (czy))
                  {
                      tmp = reszta;
                      tmp += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(tmp == 0)
                        ans++;

                      ans %= MOD;
                  }

                reszta += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                reszta %= m;

                if(str[i] - '0' + 1 == d)
                  str[i]++;
            }

          else if(d != 0)
            czy = true;
      }

    if(n == SIZE(str))
      {
          REP(i, n)
            str[i] = '9';
      }

    return ans;
}

LL oblicz(string &str)
{
    int n = SIZE(str);
    LL ans = 0;

    FORD(i, n, 1)
      ans += licz(str, i), ans %= MOD;//, cerr<<"NUMEr "<<i<<" "<<ans<<endl;

    return ans;
}

int main()
{
    int dl = 0, dl2 = 0;

    cin>>m>>d;

    scanf("%s", s);
    scanf("%s", s2);

    while(s[dl]) dl++;
    while(s2[dl2]) dl2++;

    int n = max(dl, dl2) + 2;

    potega[0] = 1 % m;

    FOR(i, 1, n)
      potega[i] = potega[i - 1] * 10, potega[i] %= m;

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[0][i % m]++;
      }

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[1][(i * 10) % m]++;
      }

    LL pot = 10;
    LL tmp = 0;

    FOR(i, 2, n)
      {
          pot *= 10;
          pot %= m;

          REP(j, 10)
            {
               if(j == d)
                 continue;

               REP(k, m)
                 {
                     tmp = (pot * j) % m;

                     if(tmp <= k)
                       {
                           dp[i][k] += dp[i - 2][k - tmp];
                       }

                     else
                       {
                           dp[i][k] += dp[i - 2][m - tmp + k];
                       }

                     dp[i][k] %= MOD;
                 }
            }
      }

    string st = minuss(s);
    string st2 = s2;

   // cerr<<st<<endl;
   // cerr<<"JEDEN "<<oblicz(st2)<<" "<<oblicz(st)<<endl;

    cout<<(oblicz(st2) - oblicz(st) + MOD) % MOD<<endl;

    return 0;
}


#include <bits/stdc++.h>

#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef vector <PII> VPII;

const LL MOD = 1e9 + 7;
const int MAXN = 2e3 + 9;

char s[MAXN];
char s2[MAXN];
LL dp[MAXN][MAXN];
LL potega[MAXN];
LL d;
LL m;
int glos;

string minuss(string str)
{
    int n = SIZE(str);
    int reszta = -1;

    for(int i = n - 1; i >= 0; i--)
      {
         if(reszta + str[i] - '0' >= 0)
           {
              str[i] += reszta;
              break;
           }

         if(reszta + str[i] - '0' < 0)
           {
              str[i] = str[i] + 10 + reszta;
              reszta = -1;
           }
      }

    string strr;
    bool czy = false;

    REP(i, n)
      {
          if(str[i] != '0')
            czy = true;

          if(czy)
            strr += str[i];
      }

    if(SIZE(strr) == 0)
      strr = "0";

    return strr;
}

LL licz(string &str, int n)
{
    int pocz = SIZE(str) - n;
    LL ans = 0;
    LL reszta = 0;
    int ost = MAXN + 1000;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 1)
            {
                if(str[i] - '0' < d)
                  {
                      if(ost == MAXN + 1000)
                        ost = i - 1;
                  }

                reszta += d * potega[n - (i - pocz) - 1];
                reszta %= m;
            }
      }

    LL tmp = 0;
    bool czy = false;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 0)
            {
                if(str[i] - '0' == d)
                  {
                      if(!czy)
                        {
                            czy = true;
                            ost = MAXN + 1000;

                            FOR(j, i + 1, n)
                              str[j] = '9';
                        }

                      str[i]--;
                  }

                REP(j, str[i] - '0')
                  {
                      if(j == d)
                        continue;

                      if(i == pocz)
                        {
                            if(j == 0)
                              continue;
                        }

                      tmp = reszta;
                      tmp += j * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(i < SIZE(str) - 2)
                        ans += dp[n - (i - pocz) - 3][(m - tmp) % m];

                      else if(tmp == 0)
                        ans++;

                      ans %= MOD;
                    //  cerr<<"CYFRA "<<j<<" "<<ans<<" "<<tmp<<"RE "<<reszta<<" "<<i<<" "<<SIZE(str) - 2<<" "<<n<<endl;
                  }

                if(ost == i)
                  break;

                if(i >= SIZE(str) - 2)
                  {
                      tmp = reszta;
                      tmp += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(tmp == 0)
                        ans++;

                      ans %= MOD;
                  }

                reszta += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                reszta %= m;

                if(str[i] - '0' + 1 == d)
                  str[i]++;
            }

          else if((!czy) && (str[i] - '0' > d))
            {//cerr<<"Co"<<endl;
                czy = true;
                ost = MAXN + 1000;

                REP(j, n)
                  str[j] = '9';
            }
      }

    return ans;
}

LL oblicz(string &str)
{
    if(SIZE(str) != glos)
      return 0;

    //cerr<<"OBLICZ "<<str<<endl;
    int n = SIZE(str);
    LL ans = 0;

    ans = licz(str, n);

   // FORD(i, n, 1)
    //  ans += licz(str, i), ans %= MOD;//, cerr<<"NUMEr "<<i<<" "<<ans<<endl;

    return ans;
}

int main()
{
    int dl = 0, dl2 = 0;

    cin>>m>>d;

    scanf("%s", s);
    scanf("%s", s2);

    while(s[dl]) dl++;
    while(s2[dl2]) dl2++;

    int n = max(dl, dl2) + 2;

    potega[0] = 1 % m;

    FOR(i, 1, n)
      potega[i] = potega[i - 1] * 10, potega[i] %= m;

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[0][i % m]++;
      }

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[1][(i * 10) % m]++;
      }

    LL pot = 10;
    LL tmp = 0;

    FOR(i, 2, n)
      {
          pot *= 10;
          pot %= m;

          REP(j, 10)
            {
               if(j == d)
                 continue;

               REP(k, m)
                 {
                     tmp = (pot * j) % m;

                     if(tmp <= k)
                       {
                           dp[i][k] += dp[i - 2][k - tmp];
                       }

                     else
                       {
                           dp[i][k] += dp[i - 2][m - tmp + k];
                       }

                     dp[i][k] %= MOD;
                 }
            }
      }

    string st = minuss(s);
    string st2 = s2;

    glos = SIZE(st2);

   // cerr<<"JEDEN "<<oblicz(st2)<<" "<<oblicz(st)<<endl;

    cout<<(oblicz(st2) - oblicz(st) + MOD) % MOD<<endl;

    return 0;
}


#include <bits/stdc++.h>

#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef vector <PII> VPII;

const LL MOD = 1e9 + 7;
const int MAXN = 2e3 + 9;

char s[MAXN];
char s2[MAXN];
LL dp[MAXN][MAXN];
LL potega[MAXN];
LL d;
LL m;
int glos;

string minuss(string str)
{
    int n = SIZE(str);
    int reszta = -1;

    for(int i = n - 1; i >= 0; i--)
      {
         if(reszta + str[i] - '0' >= 0)
           {
              str[i] += reszta;
              break;
           }

         if(reszta + str[i] - '0' < 0)
           {
              str[i] = str[i] + 10 + reszta;
              reszta = -1;
           }
      }

    string strr;
    bool czy = false;

    REP(i, n)
      {
          if(str[i] != '0')
            czy = true;

          if(czy)
            strr += str[i];
      }

    if(SIZE(strr) == 0)
      strr = "0";

    return strr;
}

LL licz(string &str, int n)
{
    int pocz = SIZE(str) - n;
    LL ans = 0;
    LL reszta = 0;
    int ost = MAXN + 1000;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 1)
            {
                if(str[i] - '0' < d)
                  {
                      if(ost == MAXN + 1000)
                        ost = i - 1;
                  }

                reszta += d * potega[n - (i - pocz) - 1];
                reszta %= m;
            }
      }

    LL tmp = 0;
    bool czy = false;

    FOR(i, pocz, SIZE(str) - 1)
      {
          if((i - pocz) % 2 == 0)
            {
                if(str[i] - '0' == d)
                  {
                      if(!czy)
                        {
                            czy = true;
                            ost = MAXN + 1000;

                            FOR(j, i + 1, n)
                              str[j] = '9';
                        }

                      str[i]--;
                  }

                REP(j, str[i] - '0')
                  {
                      if(j == d)
                        continue;

                      if(i == pocz)
                        {
                            if(j == 0)
                              continue;
                        }

                      tmp = reszta;
                      tmp += j * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(i < SIZE(str) - 2)
                        ans += dp[n - (i - pocz) - 3][(m - tmp) % m];

                      else if(tmp == 0)
                        ans++;

                      ans %= MOD;
                    //  cerr<<"CYFRA "<<j<<" "<<ans<<" "<<tmp<<"RE "<<reszta<<" "<<i<<" "<<SIZE(str) - 2<<" "<<n<<endl;
                  }

                if(ost == i)
                  break;

                if(i >= SIZE(str) - 2)
                  {
                      tmp = reszta;
                      tmp += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                      tmp %= m;

                      if(tmp == 0)
                        ans++;

                      ans %= MOD;
                  }

                reszta += (LL)(str[i] - '0') * potega[n - (i - pocz) - 1];
                reszta %= m;

                if(str[i] - '0' + 1 == d)
                  str[i]++;
            }

          else if((!czy) && (str[i] - '0' > d))
            {//cerr<<"Co"<<endl;
                czy = true;
                ost = MAXN + 1000;

                REP(j, n)
                  str[j] = '9';
            }
      }

    return ans;
}

LL oblicz(string &str)
{
    if(SIZE(str) != glos)
      return 0;

    //cerr<<"OBLICZ "<<str<<endl;
    int n = SIZE(str);
    LL ans = 0;

    ans = licz(str, n);

   // FORD(i, n, 1)
    //  ans += licz(str, i), ans %= MOD;//, cerr<<"NUMEr "<<i<<" "<<ans<<endl;

    return ans;
}

int main()
{
    int dl = 0, dl2 = 0;

    cin>>m>>d;

    scanf("%s", s);
    scanf("%s", s2);

    while(s[dl]) dl++;
    while(s2[dl2]) dl2++;

    int n = max(dl, dl2) + 2;

    potega[0] = 1 % m;

    FOR(i, 1, n)
      potega[i] = potega[i - 1] * 10, potega[i] %= m;

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[0][i % m]++;
      }

    FOR(i, 0, 9)
      {
          if(i == d)
            continue;

          dp[1][(i * 10) % m]++;
      }

    LL pot = 10;
    LL tmp = 0;

    FOR(i, 2, n)
      {
          pot *= 10;
          pot %= m;

          REP(j, 10)
            {
               if(j == d)
                 continue;

               REP(k, m)
                 {
                     tmp = (pot * j) % m;

                     if(tmp <= k)
                       {
                           dp[i][k] += dp[i - 2][k - tmp];
                       }

                     else
                       {
                           dp[i][k] += dp[i - 2][m - tmp + k];
                       }

                     dp[i][k] %= MOD;
                 }
            }
      }

    string st = minuss(s);
    string st2 = s2;

    glos = SIZE(st2);

   // cerr<<"JEDEN "<<oblicz(st2)<<" "<<oblicz(st)<<endl;

    cout<<(oblicz(st2) - oblicz(st) + MOD) % MOD<<endl;

    system("pause");    return 0;
}


#include <cstdio>
#include <cstring>
const int M = 2005;
const int MOD = 1e9+7;
int read()
{
	int x=0;
	scanf("%d",&x);
	return x;
}
int n,m,d,a[M],dp[M][M];char s[M];
int dfs(int x,int r,int up,int zero)
{
	if(!x) return !r && !zero;
	if(!up && !zero && dp[x][r]!=-1) return dp[x][r];
	int ans=0;
	for(int i=0;i<=9;i++)
	{
		if(up && i>a[x]) break;
		if(((n-x)%2==1 && i!=d) || ((n-x)%2==0 && i==d))
			continue;
		ans=(ans+dfs(x-1,(r*10+i)%m,up&&(i==a[x]),zero&&(i==0)))%MOD;
	}
	if(!up && !zero) dp[x][r]=ans;
	return ans;
}
int check()
{
	int sum=0,f=0;
	for(int i=n;i>=1;i--)
	{
		sum=(sum*10+a[i])%m;
		if((n-i)%2==1 && a[i]!=d) f=1;
		if((n-i)%2==0 && a[i]==d) f=1;
	}
	return sum==0 && f==0;
}
int work()
{
	scanf("%s",s);n=strlen(s);
	for(int i=0;i<n;i++)
		a[n-i]=s[i]-'0';
	return dfs(n,0,1,1);
}
int main()
{
	memset(dp,-1,sizeof dp);
	m=read();d=read();
	int l=work()-check(),r=work();
	printf("%d\n",(r-l+MOD)%MOD);
}


#include <cstdio>
#include <cstring>
const int M = 2005;
const int MOD = 1e9+7;
int read()
{
	int x=0,f=1;char c;
	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
int n,m,d,a[M],dp[M][M];char s[M];
int dfs(int x,int r,int up,int zero)
{
	if(!x) return !r && !zero;
	if(!up && dp[x][r]!=-1) return dp[x][r];
	int ans=0;
	for(int i=0;i<=9;i++)
	{
		if(up && i>a[x]) break;
		if(((n-x)%2==1 && i!=d) || ((n-x)%2==0 && i==d))
			continue;
		ans=(ans+dfs(x-1,(r*10+i)%m,up&&(i==a[x]),zero&&(i==0)))%MOD;
	}
	if(!up) dp[x][r]=ans;
	return ans;
}
int work()
{
	scanf("%s",s);n=strlen(s);
	for(int i=0;i<n;i++)
		a[n-i]=s[i]-'0';
	return dfs(n,0,1,1);
}
int check()
{
	int sum=0,f=0;
	for(int i=n;i>=1;i--)
	{
		sum=(sum*10+a[i])%m;
		if((n-i)%2==0 && i==d) f=1;
		if((n-i)%2==1 && i!=d) f=1;
	}
	return sum==0 && f==0;
}
int main()
{
	memset(dp,-1,sizeof dp);
	m=read();d=read();
	int l=work()-check(),r=work();
	printf("%d\n",(r-l+MOD)%MOD);
}


#include <cstdio>
#include <cstring>
const int M = 2005;
const int MOD = 1e9+7;
int read()
{
	int x=0,f=1;char c;
	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
int n,m,d,a[M],dp[M][M];char s[M];
int dfs(int x,int r,int up,int zero)
{
	if(!x) return !r && !zero;
	if(!up && !zero &&dp[x][r]!=-1) return dp[x][r];
	int ans=0;
	for(int i=0;i<=9;i++)
	{
		if(up && i>a[x]) break;
		if(((n-x)%2==1 && i!=d) || ((n-x)%2==0 && i==d))
			continue;
		ans=(ans+dfs(x-1,(r*10+i)%m,up&&(i==a[x]),zero&&(i==0)))%MOD;
	}
	if(!up) dp[x][r]=ans;
	return ans;
}
int work()
{
	scanf("%s",s);n=strlen(s);
	for(int i=0;i<n;i++)
		a[n-i]=s[i]-'0';
	return dfs(n,0,1,1);
}
int check()
{
	int sum=0,f=0;
	for(int i=n;i>=1;i--)
	{
		sum=(sum*10+a[i])%m;
		if((n-i)%2==0 && i==d) f=1;
		if((n-i)%2==1 && i!=d) f=1;
	}
	return sum==0 && f==0;
}
int main()
{
	memset(dp,-1,sizeof dp);
	m=read();d=read();
	int l=work()-check(),r=work();
	printf("%d\n",(r-l+MOD)%MOD);
}


#include <cstdio>
#include <cstring>
const int M = 2005;
const int MOD = 1e9+7;
#define int long long
int read()
{
	int x=0,f=1;char c;
	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
int n,m,d,a[M],dp[M][M];char s[M];
int dfs(int x,int r,int up,int zero)
{
	if(!x) return !r && !zero;
	if(!up && !zero &&dp[x][r]!=-1) return dp[x][r];
	int ans=0;
	for(int i=0;i<=9;i++)
	{
		if(up && i>a[x]) break;
		if(((n-x)%2==1 && i!=d) || ((n-x)%2==0 && i==d))
			continue;
		ans=(ans+dfs(x-1,(r*10+i)%m,up&&(i==a[x]),zero&&(i==0)))%MOD;
	}
	if(!up && !zero) dp[x][r]=ans;
	return ans;
}
int work()
{
	scanf("%s",s);n=strlen(s);
	for(int i=0;i<n;i++)
		a[n-i]=s[i]-'0';
	return dfs(n,0,1,1);
}
int check()
{
	int sum=0,f=0;
	for(int i=n;i>=1;i--)
	{
		sum=(sum*10+a[i])%m;
		if((n-i)%2==0 && i==d) f=1;
		if((n-i)%2==1 && i!=d) f=1;
	}
	return sum==0 && f==0;
}
signed main()
{
	memset(dp,-1,sizeof dp);
	m=read();d=read();
	int l=work()-check(),r=work();
	printf("%lld\n",(r-l+MOD)%MOD);
}


#include <cstdio>
#include <cstring>
#define int long long
const int M = 2005;
const int MOD = 1e9+7;
int read()
{
	int x=0,f=1;char c;
	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
int n,m,d,l,r,p[M],a[M],dp[M][M];char s[M];
int dfs(int x,int r,int up,int zero)
{
	if(!x) return !r && !zero;
	if(dp[x][r]!=-1 && !up && !zero) return dp[x][r];
	int ans=0;
	for(int i=0;i<=9;i++)
	{
		if(up && i>a[x]) break;
		if(((n-x)%2==1 && i!=d) || ((n-x)%2==0 && i==d))
			continue;
		int t=i*p[x-1]%m;
		ans=(ans+dfs(x-1,(r-t+m)%m,up&&(i==a[x]),zero&&(i==0)))%MOD;
	}
	if(!up && !zero) dp[x][r]=ans;
	return ans;
}
int work(int f)
{
	scanf("%s",s);n=strlen(s);
	for(int i=0;i<n;i++)
		a[n-i]=s[i]-'0';
	int sum=0;
	for(int i=0;i<n;i++)
	{
		int x=a[i]-'0';
		if((i+1)&1) {if(x==d) f=1;}
		else {if(x!=d) f=1;}
		sum=(sum*10+x)%m;
	}
	return dfs(n,0,1,1)-(sum==0 && f==0);
}
signed main()
{
	memset(dp,-1,sizeof dp);
	m=read();d=read();
	p[0]=1;
	for(int i=1;i<=2000;i++)
		p[i]=p[i-1]*10%MOD;
	int l=work(0),r=work(1);
	printf("%lld\n",(r-l+MOD)%MOD);
}


#include <cstdio>
#include <cstring>
const int M = 2005;
const int MOD = 1e9+7;
int read()
{
	int x=0;
	scanf("%d",&x);
	return x;
}
int n,m,d,a[M],dp[M][M];char s[M];
int dfs(int x,int r,int up,int zero)
{
	if(!x) return !r && !zero;
	if(!up && !zero && dp[x][r]!=-1) return dp[x][r];
	int ans=0;
	for(int i=0;i<=9;i++)
	{
		if(up && i>a[x]) break;
		if(((n-x)%2==1 && i!=d) || ((n-x)%2==0 && i==d))
			continue;
		ans=(ans+dfs(x-1,(r*10+i)%m,up&&(i==a[x]),zero&&(i==0)));
	}
	if(!up && !zero) dp[x][r]=ans;
	return ans;
}
int check()
{
	int sum=0,f=0;
	for(int i=n;i>=1;i--)
	{
		sum=(sum*10+a[i])%m;
		if((n-i)%2==1 && a[i]!=d) f=1;
		if((n-i)%2==0 && a[i]==d) f=1;
	}
	return sum==0 && f==0;
}
int work()
{
	scanf("%s",s);n=strlen(s);
	for(int i=0;i<n;i++)
		a[n-i]=s[i]-'0';
	return dfs(n,0,1,1);
}
int main()
{
	memset(dp,-1,sizeof dp);
	m=read();d=read();
	int l=work()-check(),r=work();
	printf("%d\n",(r-l+MOD)%MOD);
}


#include <cstdio>
#include <cstring>
#define int long long
const int M = 2005;
const int MOD = 1e9+7;
int read()
{
	int x=0,f=1;char c;
	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
int n,m,d,l,r,p[M],a[M],dp[M][M];char s[M];
int dfs(int x,int r,int up,int zero)
{
	if(!x) return !r && !zero;
	if(dp[x][r]!=-1 && !up && !zero) return dp[x][r];
	int ans=0;
	for(int i=0;i<=9;i++)
	{
		if(up && i>a[x]) break;
		if(((n-x)%2==1 && i!=d) || ((n-x)%2==0 && i==d))
			continue;
		int t=i*p[x-1]%m;
		ans=(ans+dfs(x-1,(r-t+m)%m,up&&(i==a[x]),zero&&(i==0)))%MOD;
	}
	if(!up && !zero) dp[x][r]=ans;
	return ans;
}
int work(int f)
{
	scanf("%s",s);n=strlen(s);
	for(int i=0;i<n;i++)
		a[n-i]=s[i]-'0';
	int sum=0;
	for(int i=0;i<n;i++)
	{
		int x=s[i]-'0';
		if((i+1)&1) {if(x==d) f=1;}
		else {if(x!=d) f=1;}
		sum=(sum*10+x)%m;
	}
	return dfs(n,0,1,1)-(sum==0 && f==0);
}
signed main()
{
	memset(dp,-1,sizeof dp);
	m=read();d=read();
	p[0]=1;
	for(int i=1;i<=2000;i++)
		p[i]=p[i-1]*10%MOD;
	int l=work(0),r=work(1);
	printf("%lld\n",(r-l+MOD)%MOD);
}


#include <cstdio>
#include <cstring>
#define int long long
const int M = 2005;
const int MOD = 1e9+7;
int read()
{
	int x=0,f=1;char c;
	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
int n,m,d,l,r,a[M],dp[M][M];char s[M];
int dfs(int x,int r,int up,int zero)
{
	if(!x) return !r && !zero;
	if(dp[x][r]!=-1 && !up && !zero) return dp[x][r];
	int ans=0;
	for(int i=0;i<=9;i++)
	{
		if(up && i>a[x]) break;
		if(((n-x)%2==1 && i!=d) || ((n-x)%2==0 && i==d))
			continue;
		ans=(ans+dfs(x-1,(10*r+i)%m,up&&(i==a[x]),zero&&(i==0)))%MOD;
	}
	if(!up && !zero) dp[x][r]=ans;
	return ans;
}
int work(int f)
{
	scanf("%s",s);n=strlen(s);
	for(int i=0;i<n;i++)
		a[n-i]=s[i]-'0';
	int sum=0;
	for(int i=0;i<n;i++)
	{
		int x=s[i]-'0';
		if((i+1)&1) {if(x==d) f=1;}
		else {if(x!=d) f=1;}
		sum=(sum*10+x)%m;
	}
	return dfs(n,0,1,1)-(sum==0 && f==0);
}
signed main()
{
	memset(dp,-1,sizeof dp);
	m=read();d=read();
	int l=work(0),r=work(1);
	printf("%lld\n",(r-l+MOD)%MOD);
}


#include <cstdio>
#include <cstring>
#define int long long
const int M = 2005;
const int MOD = 1e9+7;
int read()
{
	int x=0,f=1;char c;
	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
int n,m,d,l,r,p[M],a[M],dp[M][M];char s[M];
int dfs(int x,int r,int up,int zero)
{
	if(!x) return !r && !zero;
	if(dp[x][r]!=-1 && !up && !zero) return dp[x][r];
	int ans=0;
	for(int i=0;i<=9;i++)
	{
		if(up && i>a[x]) break;
		if(((n-x)%2==1 && i!=d) || ((n-x)%2==0 && i==d))
			continue;
		int t=i*p[x-1]%m;
		ans=(ans+dfs(x-1,(r-t+m)%m,up&&(i==a[x]),zero&&(i==0)))%MOD;
	}
	if(!up && !zero) dp[x][r]=ans;
	return ans;
}
int work()
{
	scanf("%s",s);n=strlen(s);
	for(int i=0;i<n;i++)
		a[n-i]=s[i]-'0';
	return dfs(n,0,1,1);
}
signed main()
{
	memset(dp,-1,sizeof dp);
	m=read();d=read();
	p[0]=1;
	for(int i=1;i<=2000;i++)
		p[i]=p[i-1]*10%MOD;
	int l=work(),r=work();
	printf("%lld\n",(r-l+MOD)%MOD);
}