#include<bits/stdc++.h>
#define ll long long int
#define pii pair<ll,ll>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define M 500005
#define mod 1000000007
#define inf LLONG_MAX
using namespace std;
string s;
int n,m,k;
ll dp[2005][2005][2];
ll solve(ll i,ll rem,ll tight)
{
	if(i==n)
	{
		if(rem==0)
		return 1;
		else
		return 0;
	}
	if(dp[i][rem][tight]==-1)
	{
		dp[i][rem][tight]=0;
		if(i&1)
		{
			if(tight)
			{
				if(s[i]-48>k)
				dp[i][rem][tight]=solve(i+1,(10*rem+k)%m,0);
				else if(s[i]-48==k)
				dp[i][rem][tight]=solve(i+1,(10*rem+k)%m,1);
			}
			else
			dp[i][rem][tight]=solve(i+1,(10*rem+k)%m,tight);
		}
		else
		{
			if(tight)
			{
				int j;
				for(j=0;j<(s[i]-48);j++)
				{
					if(j!=k)
					{
						dp[i][rem][tight]+=solve(i+1,(10*rem+j)%m,0);
						dp[i][rem][tight]%=mod;
					}
				}
				if(j!=k)
				{
					dp[i][rem][tight]+=solve(i+1,(10*rem+j),1);
					dp[i][rem][tight]%=mod;
				}
			}
			else
			{
				for(int j=0;j<10;j++)
				{
					if(j!=k)
					{
						dp[i][rem][tight]+=solve(i+1,(10*rem+j)%m,0);
						dp[i][rem][tight]%=mod;
					}
				}
			}
		}
	}
	return dp[i][rem][tight];
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll t,q,i,j,x,y,z;
	string a,b;
	cin>>m>>k;
	cin>>a;
	cin>>b;
	z=0;
	int flag=1;
	n=a.length();
	for(i=0;i<n;i++)
	{
		if(i&1)
		{
			if(a[i]!=k+'0')
			flag=0;
		}
		else
		{
			if(a[i]==k+'0')
			flag=0;
		}
		z=(z*10+(a[i]-'0'));
		z%=m;
	}
	if(z!=0)
	flag=0;
	s=a;
	memset(dp,-1,sizeof dp);
	x=solve(0,0,1);
	s=b;
	memset(dp,-1,sizeof dp);
	y=solve(0,0,1);
	//cout<<x<<" "<<y<<" "<<flag<<"\n";
	x=y-x+mod;
	x%=mod;
	cout<<x;
}

// Name - Hemant Chowdhury
// Arise, Awake And Stop Not Till The Goal Is Reached!
// If I fail,I will stand again;If I win,I will move farther


#include<bits/stdc++.h>
#define ll long long int
#define pii pair<ll,ll>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define M 500005
#define mod 1000000007
#define inf LLONG_MAX
using namespace std;
string s;
int n,m,k;
ll dp[2005][2005][2];
ll solve(ll i,ll rem,ll tight)
{
	if(i==n)
	{
		if(rem==0)
		return 1;
		else
		return 0;
	}
	if(dp[i][rem][tight]==-1)
	{
		dp[i][rem][tight]=0;
		if(i&1)
		{
			if(tight)
			{
				if(s[i]-48>k)
				dp[i][rem][tight]=solve(i+1,(10*rem+k)%m,0);
				else if(s[i]-48==k)
				dp[i][rem][tight]=solve(i+1,(10*rem+k)%m,1);
			}
			else
			dp[i][rem][tight]=solve(i+1,(10*rem+k)%m,tight);
		}
		else
		{
			if(tight)
			{
				int j;
				for(j=0;j<(s[i]-48);j++)
				{
					if(j!=k)
					{
						dp[i][rem][tight]+=solve(i+1,(10*rem+j)%m,0);
						dp[i][rem][tight]%=mod;
					}
				}
				if(j!=k)
				{
					dp[i][rem][tight]+=solve(i+1,(10*rem+j),1);
					dp[i][rem][tight]%=mod;
				}
			}
			else
			{
				for(int j=0;j<10;j++)
				{
					if(j!=k)
					{
						dp[i][rem][tight]+=solve(i+1,(10*rem+j)%m,0);
						dp[i][rem][tight]%=mod;
					}
				}
			}
		}
	}
	return dp[i][rem][tight];
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll t,q,i,j,x,y,z;
	string a,b;
	cin>>m>>k;
	cin>>a;
	cin>>b;
	z=0;
	int flag=1;
	n=a.length();
	for(i=0;i<n;i++)
	{
		if(i&1)
		{
			if(a[i]!=k+'0')
			flag=0;
		}
		else
		{
			if(a[i]==k+'0')
			flag=0;
		}
		z=(z*10+(a[i]-'0'));
		z%=m;
	}
	if(z!=0)
	flag=0;
	s=a;
	memset(dp,-1,sizeof dp);
	x=solve(0,0,1);
	s=b;
	memset(dp,-1,sizeof dp);
	y=solve(0,0,1);
	//cout<<x<<" "<<y<<" "<<flag<<"\n";
	x=y-x+mod+flag;
	x%=mod;
	cout<<x;
}

// Name - Hemant Chowdhury
// Arise, Awake And Stop Not Till The Goal Is Reached!
// If I fail,I will stand again;If I win,I will move farther


#include<bits/stdc++.h>
#define ll long long int
#define pii pair<ll,ll>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define M 500005
#define mod 1000000007
#define inf LLONG_MAX
using namespace std;
string s;
int n,m,k;
ll dp[2005][2005][2];
ll solve(ll i,ll rem,ll tight)
{
	if(i==n)
	{
		if(rem==0)
		return 1;
		else
		return 0;
	}
	if(dp[i][rem][tight]==-1)
	{
		dp[i][rem][tight]=0;
		if(i&1)
		{
			if(tight)
			{
				if(s[i]-48>k)
				dp[i][rem][tight]=solve(i+1,(10*rem+k)%m,0);
				else if(s[i]-48==k)
				dp[i][rem][tight]=solve(i+1,(10*rem+k)%m,1);
			}
			else
			dp[i][rem][tight]=solve(i+1,(10*rem+k)%m,tight);
		}
		else
		{
			if(tight)
			{
				int j;
				for(j=0;j<(s[i]-48);j++)
				{
					if(j!=k)
					{
						dp[i][rem][tight]+=solve(i+1,(10*rem+j)%m,0);
						dp[i][rem][tight]%=mod;
					}
				}
				if(j!=k)
				{
					dp[i][rem][tight]+=solve(i+1,(10*rem+j),1);
					dp[i][rem][tight]%=mod;
				}
			}
			else
			{
				for(int j=0;j<10;j++)
				{
					if(j!=k)
					{
						dp[i][rem][tight]+=solve(i+1,(10*rem+j)%m,0);
						dp[i][rem][tight]%=mod;
					}
				}
			}
		}
	}
	return dp[i][rem][tight];
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll t,q,i,j,x,y,z;
	string a,b;
	cin>>m>>k;
	cin>>a;
	cin>>b;
	z=0;
	int flag=1;
	n=a.length();
	for(i=0;i<n;i++)
	{
		if(i&1)
		{
			if(a[i]!=k+'0')
			flag=0;
		}
		z=(z*10+(a[i]-'0'));
		z%=m;
	}
	if(z!=0)
	flag=0;
	s=a;
	memset(dp,-1,sizeof dp);
	x=solve(0,0,1);
	s=b;
	memset(dp,-1,sizeof dp);
	y=solve(0,0,1);
	//cout<<x<<" "<<y<<" "<<flag<<"\n";
	x=y-x+mod+flag;
	x%=mod;
	cout<<x;
}

// Name - Hemant Chowdhury
// Arise, Awake And Stop Not Till The Goal Is Reached!
// If I fail,I will stand again;If I win,I will move farther


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = (int)(1e9 + 7);
int dp[2005][2005][2] , bit[2005];
int m, d;
string a, b;

void add(int &a, int b){
    if(b >= MOD) b -= MOD;
    a += b;
    if(a >= MOD) a -= MOD;
}

int dfs(int pos, int num, int o, int f, int zero, int odd){
    if(pos < 0) return !num;
    int &ans = dp[pos][num][o];
    if(!f && zero && ans != -1) return ans;
    int last = f ? bit[pos] : 9;
    int res = 0;
    for(int i = 0; i <= last; i++){
        int nxto = o;
        if(zero){
            if(odd && i == d) continue;
            if(!odd && i != d) continue;
        }
        else if(i){
            if(i == d) continue;
            odd = 1;
            nxto = pos & 1;
        }
        add(res, dfs(pos - 1, (num * 10 + i) % m, nxto, f && i==last, zero || i, !odd));
    }
    if(!f && zero) ans = res;
    return res;
}

int Count(string& s, int f){
    int len = s.length();
    for(int i = 0; i < len; i++){
        bit[i] = s[len - i - 1] - '0';
    }
    if(f){
        for(int i = 0; i < len; i++){
            if(bit[i] > 0) { bit[i]--; break; }
            bit[i] = 9;
        }
        while(len != 1 && !bit[len - 1]) len--;
    }
    return dfs(len - 1, 0, 0, 1, 0, 0);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin >> m >> d >> a >> b;
    memset(dp, -1, sizeof dp);
    cout << Count(b, 0) - Count(a, 1) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = (int)(1e9 + 7);
int dp[2005][2005][2] , bit[2005];
int m, d;
string a, b;

void add(int &a, int b){
    if(b >= MOD) b -= MOD;
    a += b;
    if(a >= MOD) a -= MOD;
}

int dfs(int pos, int num, int o, int f, int zero, int odd){
    if(pos < 0) return !num;
    int &ans = dp[pos][num][o];
    if(!f && zero && ans != -1) return ans;
    int last = f ? bit[pos] : 9;
    int res = 0;
    for(int i = 0; i <= last; i++){
        int nxto = o;
        if(zero){
            if(odd && i == d) continue;
            if(!odd && i != d) continue;
        }
        else if(i){
            if(i == d) continue;
            odd = 1;
            nxto = pos & 1;
        }
        add(res, dfs(pos - 1, (num * 10 + i) % m, nxto, f && i==last, zero || i, !odd));
    }
    if(!f && zero) ans = res;
    return res;
}

int Count(string& s, int f){
    int len = s.length();
    for(int i = 0; i < len; i++){
        bit[i] = s[len - i - 1] - '0';
    }
    if(f){
        for(int i = 0; i < len; i++){
            if(bit[i] > 0) { bit[i]--; break; }
            bit[i] = 9;
        }
        while(len != 1 && !bit[len - 1]) len--;
    }
    return dfs(len - 1, 0, 0, 1, 0, 0);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin >> m >> d >> a >> b;
    memset(dp, -1, sizeof dp);
    cout << (Count(b, 0) - Count(a, 1) + MOD) % MOD << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = (int)(1e9 + 7);
int dp[2005][2005][2] , bit[2005], ten[2005];
int m, d;
string a, b;

void add(int &a, int b){
    if(b >= MOD) b -= MOD;
    a += b;
    if(a >= MOD) a -= MOD;
}

void DP(){
    int n = b.size();
    ten[0] = 1;
    for(int i = 1; i <= n; i++) ten[i] = ten[i - 1] * 10 % m;
    dp[0][0][0] = dp[0][0][1] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < m; j++){
            int x = i & 1 ? 0 : 1;
            int y = i & 1 ? 1 : 0;
            for(int k = 0; k <= 9; k++){
                if(k != d){
                    add(dp[i][(k * ten[i - 1] + j) % m][x], dp[i - 1][j][x]);
                }else{
                    add(dp[i][(k * ten[i - 1] + j) % m][y], dp[i - 1][j][y]);
                }
            }
        }
    }
}

int Count(string& s, int f){
    int len = s.length();
    for(int i = 1; i <= len; i++){
        bit[i] = s[len - i] - '0';
    }
    if(f){
        for(int i = 1; i <= len; i++){
            if(bit[i] > 0) { bit[i]--; break; }
            bit[i] = 9;
        }
        while(len != 1 && !bit[len]) len--;
    }
    if(len == 1 && !bit[len]) return 0; //0不能被计算进去
    int ans = 0, x, t = 1, mod = 0;
    for(int i = len; i >= 1; i--){
        for(int j = 1; j <= bit[i]; j++){
            if(j == d) continue; //odd! can't put digit d
            for(int md = 0; md < m; md++){
                if((j * ten[i - 1] + md) % m == 0){
                    add(ans, dp[i - 1][md][(i - 1) & 1]);
                }
            }
        }
    }
    if(len == 1) t = 0;
    for(int i = 1; i <= len; i++){
        if(!((len - i + 1) & 1) && bit[i] != d) t = 0;
        mod = (mod * 10 + bit[i]) % m;
    }
    if(mod != 0) t = 0;
    add(ans, t);
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin >> m >> d >> a >> b;
    DP();
    cout << Count(b, 0) - Count(a, 1) << endl;
    return 0;
}


# include <stdio.h>
# include <string.h>
# define MOD 1000000007
# define MAXN 2005

char l[MAXN], r[MAXN];
int m, d, wei[MAXN], dp[MAXN][MAXN][10], len;

int check(char *s)
{
	int mod=0;
	len=strlen(s);
	for (int i=0; i<len; ++i) {
		if ((i&1)==0 && s[i]-'0'==d) return 0;
		if ((i&1) && s[i]-'0'!=d) return 0;
		mod=(mod*10+s[i]-'0')%m;
	}
	return mod==0;
}
int dfs(int pos, int pre, int mod, int limit, int zero, int sum)
{
	if (pos==-1) return mod==0;
	if (!limit && !zero && ~dp[pos][mod][pre]) return dp[pos][mod][pre];
	int up= limit?wei[pos]:9, ans=0, down =zero?1:0;
	for (int i=down; i<=up; ++i) {
		if (i==d && ((len-pos)&1)) continue;
		if (((len-pos)&1)==0 && i!=d) continue;
		ans=(ans+dfs(pos-1,i,(mod*10+i)%m,limit&&i==up,zero&&i==0,sum*10+i))%MOD;
	}
	if (!limit && !zero) return dp[pos][mod][pre]=ans;
	return ans;
}
int sol(char *s)
{
	int pos=0;
	len=strlen(s);
	for (int i=len-1; i>=0; --i) wei[pos++]=s[i]-'0';
	return dfs(pos-1,0,0,1,1,0);
}
int main ()
{
	scanf("%d%d%s%s",&m,&d,l,r);
	memset(dp,-1,sizeof(dp));
	printf("%d\n",(sol(r)-sol(l)+check(l)+MOD)%MOD);
	return 0;
}


# include <stdio.h>
# include <string.h>
# define MOD 1000000007
# define MAXN 2005

char l[MAXN], r[MAXN];
int m, d, wei[MAXN], dp[MAXN][MAXN][10], len;

int check(char *s)
{
	int mod=0;
	len=strlen(s);
	for (int i=0; i<len; ++i) {
		if ((i&1)==0 && s[i]-'0'==m) return 0;
		mod=(mod+s[i]-'0')%m;
	}
	return mod==0;
}
int dfs(int pos, int pre, int mod, int limit, int zero, int sum)
{
	if (pos==-1) return mod==0;
	if (!limit && !zero && ~dp[pos][mod][pre]) return dp[pos][mod][pre];
	int up= limit?wei[pos]:9, ans=0, down =zero?1:0;
	for (int i=down; i<=up; ++i) {
		if (i==d && ((len-pos)&1)) continue;
		if (((len-pos)&1)==0 && i!=d) continue;
		ans=(ans+dfs(pos-1,i,(mod*10+i)%m,limit&&i==up,zero&&i==0,sum*10+i))%MOD;
	}
	if (!limit && !zero) return dp[pos][mod][pre]=ans;
	return ans;
}
int sol(char *s)
{
	int pos=0;
	len=strlen(s);
	for (int i=len-1; i>=0; --i) wei[pos++]=s[i]-'0';
	return dfs(pos-1,0,0,1,1,0);
}
int main ()
{
	scanf("%d%d%s%s",&m,&d,l,r);
	memset(dp,-1,sizeof(dp));
	printf("%d\n",(sol(r)-sol(l)+check(l)+MOD)%MOD);
	return 0;
}


# include <stdio.h>
# include <string.h>
# define MOD 1000000007
# define MAXN 2005

char l[MAXN], r[MAXN];
int m, d, wei[MAXN], dp[MAXN][MAXN][10], len;

int check(char *s)
{
	int mod=0;
	len=strlen(s);
	for (int i=0; i<len; ++i) {
		if ((i&1)==0 && s[i]-'0'==m) return 0;
		if ((i&1) && s[i]-'0'!=m) return 0;
		mod=(mod*10+s[i]-'0')%m;
	}
	return mod==0;
}
int dfs(int pos, int pre, int mod, int limit, int zero, int sum)
{
	if (pos==-1) return mod==0;
	if (!limit && !zero && ~dp[pos][mod][pre]) return dp[pos][mod][pre];
	int up= limit?wei[pos]:9, ans=0, down =zero?1:0;
	for (int i=down; i<=up; ++i) {
		if (i==d && ((len-pos)&1)) continue;
		if (((len-pos)&1)==0 && i!=d) continue;
		ans=(ans+dfs(pos-1,i,(mod*10+i)%m,limit&&i==up,zero&&i==0,sum*10+i))%MOD;
	}
	if (!limit && !zero) return dp[pos][mod][pre]=ans;
	return ans;
}
int sol(char *s)
{
	int pos=0;
	len=strlen(s);
	for (int i=len-1; i>=0; --i) wei[pos++]=s[i]-'0';
	return dfs(pos-1,0,0,1,1,0);
}
int main ()
{
	scanf("%d%d%s%s",&m,&d,l,r);
	memset(dp,-1,sizeof(dp));
	printf("%d\n",(sol(r)-sol(l)+check(l)+MOD)%MOD);
	return 0;
}


/*************************************************************************
	> File Name: 628d.cpp
	> Author: Severus Qin
	> Mail: qinhuapeng425@gmail.com
	> Created Time: 2016年03月29日 星期二 21时23分46秒
 ************************************************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int MOD = (int)1e9 + 7;

string a, b;
int dp[2001][2001][2][2], m, d;

int dfs(int index, int mod, int bit, int sm) {
    if (index == b.size()) return mod == 0;
    if (dp[index][mod][bit][sm] != -1) {
        return dp[index][mod][bit][sm];
    }
    long long ans = 0;
    for (int digit = 0; digit < 10; digit++) {
        if (!(index & 1) && digit == d) continue;
        if ((index & 1) && digit != d) continue;
        if (digit < (a[index] - '0') && !bit) continue;
        if (digit > (b[index] - '0') && !sm) continue;
        ans += dfs(index + 1, ((mod * 10) + digit) % m, bit | (digit > a[index] - '0'), sm | (digit < b[index] - '0')) % MOD;
    }
    ans %= MOD;
    return dp[index][mod][bit][sm] = ans;
}

int main() {
    memset(dp, -1, sizeof(dp));
    cin >> m >> d >> a >> b;
    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}


/*************************************************************************
	> File Name: 628d.cpp
	> Author: Severus Qin
	> Mail: qinhuapeng425@gmail.com
	> Created Time: 2016年03月29日 星期二 21时23分46秒
 ************************************************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int MOD = (int)1e9 + 7;

string a, b;
int dp[2001][2001][2][2], m, d;

int dfs(int index, int mod, int bit, int sm) {
    if (index == b.size()) return mod == 0;
    if (dp[index][mod][bit][sm] != -1) {
        return dp[index][mod][bit][sm];
    }
    long long ans = 0;
    for (int digit = 0; digit < 10; digit++) {
        if (!(index & 1) && digit == d) continue;
        if ((index & 1) && digit != d) continue;
        if (digit < (a[index] - '0') && !bit) continue;
        if (digit > (b[index] - '0') && !sm) continue;
        ans += dfs(index + 1, ((mod * 10) + digit) % m, bit | (digit > a[index] - '0'), (digit < b[index] - '0')) % MOD;
    }
    return dp[index][mod][bit][sm] = ans;
}

int main() {
    memset(dp, -1, sizeof(dp));
    cin >> m >> d >> a >> b;
    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}


/*************************************************************************
	> File Name: 628d.cpp
	> Author: Severus Qin
	> Mail: qinhuapeng425@gmail.com
	> Created Time: 2016年03月29日 星期二 21时23分46秒
 ************************************************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int MOD = (int)1e9 + 7;

string a, b;
int dp[2001][2001][2][2], m, d;

int dfs(int index, int mod, int bit, int sm) {
    if (index == b.size()) return mod == 0;
    if (dp[index][mod][bit][sm] != -1) {
        return dp[index][mod][bit][sm];
    }
    long long ans = 0;
    for (int digit = 0; digit < 10; digit++) {
        if (!(index & 1) && digit == d) continue;
        if ((index & 1) && digit != d) continue;
        if (digit < (a[index] - '0') && !bit) continue;
        if (digit > (b[index] - '0') && !sm) continue;
        ans += dfs(index + 1, ((mod * 10) + digit) % m, bit | (digit > a[index] - '0'), (digit < b[index] - '0')) % MOD;
    }
    ans %= MOD;
    return dp[index][mod][bit][sm] = ans;
}

int main() {
    memset(dp, -1, sizeof(dp));
    cin >> m >> d >> a >> b;
    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
int a[maxn];
int num[maxn];
int sum[maxn];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]<=m)
            num[a[i]]++;
    }
    for(int i=1;i<=m;i++)
    {
        if(num[i])
        {
            for(int j=i;j<=m;j+=i)
                sum[j]+=num[i];
        }
    }
    int maxx=0,maxval=0;
    for(int i=1;i<=m;i++)
    {
        if(sum[i]&&maxx<sum[i])
        {
            maxval=i;
            maxx=sum[i];
        }
    }
    if(maxx==0)
        printf("1 0\n");
    else
    {
        int cnt=0;
        printf("%d %d\n",maxval,maxx );
        for(int i=1;i<=n;i++)
        {
            if(maxval%a[i]==0)
            {
                if(cnt)
                    printf(" ");
                printf("%d",i );
                ++cnt;
            }
        }
        printf("\n");
    }
}


/*"μ'ic Forever!"*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
#define LL long long
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int N=2e3+5;
const int mod=1e9+7;
int m,d,l,bit[N];
LL dp[N][N];
char a[N],b[N];
LL dfs(int p,int r,int f)
{
	if(p==l)
		return r==0;
	if(!f && dp[p][r]!=-1)
		return dp[p][r];
	LL res=0;
	int en=(f?bit[p]:9);
	for(int i=0;i<=en;i++)
	{
		if((p&1)==(i==d))
			res=(res+dfs(p+1,(r*10+i)%m,f && i==en))%mod;
	}
	return f?res:dp[p][r]=res;
}
LL solve(char *s)
{
	for(int i=0;i<l;i++)
		bit[i]=s[i]-'0';
	return dfs(0,0,1);
}
int ok(char *s)
{
	int r=0;
	for(int i=0;i<l;i++)
	{
		int v=s[i]-'0';
		r=(r*10+v)%m;
		if((i&1)==(v!=d))
			return 0;
	}
	return r==0;
}
int main()
{
	/*clock_t start,finish;
	  double totaltime;
	  start=clock();*/
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	memset(dp,-1,sizeof dp);
	scanf("%d%d%s%s",&m,&d,a,b);
	l=strlen(a);
	printf("%I64d",(solve(b)-solve(a)+ok(a)+mod)%mod);
	/*finish=clock();
	  totaltime=(double)(finish-start)/CLOCKS_PER_SEC;
	  printf("\n%dms",(int)(totaltime*1000));*/
	return 0;
}


/*"μ'ic Forever!"*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
#define LL long long
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1e9+7;
const int N=2005;
int bit[N],dp[N][10][N][2],d,m;
char a[N],b[N];
int solve(char *s)
{
	int l=strlen(s),res=0;
	for(int i=0;i<l;i++)
		for(int j=1;j<(i?10:s[0]-'0');j++)
			res=(res+dp[l-i][j][0][0])%mod;
	if(s[0]==d+'0')
		return res;
	int x=(s[0]-'0')*bit[l]%m;
	for(int i=1;i<l;x=(x+bit[l-i]*(s[i]-'0'))%m,i++)
	{
		if(i%2)
			for(int j=0;j<s[i]-'0';j++)
				res=(res+(j==d?0:dp[l-i][j][(m-x)][1]))%mod;
		else
			res=(res+dp[l-i][d][(m-x)][1])%mod;
		if(s[i]==d+'0')
			return res;
	}
	return res;
}
int main()
{
	/*clock_t start,finish;
	  double totaltime;
	  start=clock();*/
	scanf("%d%d",&m,&d);
	bit[1]=1;
	for(int i=2;i<N;i++)
		bit[i]=bit[i-1]*10%m;
	for(int i=0;i<10;i++)
		dp[1][i][i%m][0]=(i!=d),dp[1][i][i%m][1]=(i==d);
	for(int i=2;i<N;i++)
		for(int j=0;j<2;j++)
			for(int k=0;k<10;k++)
				if(k!=d)
					for(int l=0;l<m;l++)
						dp[i][j?d:k][l][j]=(dp[i-1][j?k:d][((l-bit[i]*(j?d:k))%m+m)%m][j^1]+dp[i][j?d:k][l][j])%mod;
	scanf("%s%s",a,b);
	int l=strlen(b),x=l-1;
	while(b[x]=='9' && x>=0)
		b[x--]='0';
	if(x==-1)
		for(int i=0;i<=l;i++)
			b[i]=(i==0)+'0';
	printf("%d",solve(b)-solve(a));
	/*finish=clock();
	  totaltime=(double)(finish-start)/CLOCKS_PER_SEC;
	  printf("\n%dms",(int)(totaltime*1000));*/
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<bitset>
#include<algorithm>
using namespace std;
typedef long long ll;
#define inf 99999999
#define MOD 1000000007
char s1[2005],s2[2005];
int wei[2005];
ll dp[2005][2005][2];
int m,d;
void add(ll& x,ll y) {
    x += y;
    if(x>=MOD) x-=MOD;
}

ll dfs(int pos,int yushu,int oushu,int flag,int zero)
{
    int i,j;
    if(pos==-1){
        if(zero==1)return 0;
        if(yushu==0)return 1;
        else return 0;
    }
    if(!flag && !zero && dp[pos][yushu][oushu]!=-1){
        return dp[pos][yushu][oushu];
    }

    int ed=flag?wei[pos]:9;
    ll ans=0;
    if(zero==1){
        add(ans,dfs(pos-1,yushu,oushu,0,1));
        for(i=1;i<=ed;i++){
            if(i!=d)add(ans,dfs(pos-1,(yushu*10+i)%m,1^oushu,flag&&wei[pos]==i,0) );
        }
    }
    else{
        if(oushu){
            if(d<=ed)add(ans,dfs(pos-1,(yushu*10+d)%m,1^oushu,flag&&wei[pos]==d,0) );
        }
        else{
            for(i=0;i<=ed;i++){
                if(i!=d)add(ans,dfs(pos-1,(yushu*10+i)%m,1^oushu,flag&&wei[pos]==i,0) );
            }
        }
    }
    if(!flag && !zero){
        dp[pos][yushu][oushu]=ans;
    }
    return ans;
}

ll solve(char s[])
{
    int len,i,j;
    len=strlen(s);
    for(i=len-1;i>=0;i--){
        wei[i]=s[i]-'0';
    }
    return dfs(len-1,0,0,1,1);
}

int main()
{
    int n,i,j,len1,len2;
    while(scanf("%d%d",&m,&d)!=EOF)
    {
        scanf("%s%s",s1,s2);
        len1=strlen(s1);
        reverse(s1,s1+len1);
        for(i=0;i<len1;i++){
            if(s1[i]=='0'){
                s1[i]='9';
            }
            else{
                s1[i]--;break;
            }
        }
        if(s1[len1-1]=='0'){
            s1[len1-1]='\0';
            len1--;
        }

        len2=strlen(s2);
        reverse(s2,s2+len2);
        memset(dp,-1,sizeof(dp));
        ll num1=solve(s1);
        ll num2=solve(s2);
        printf("%I64d\n",((num2-num1)%MOD+MOD)%MOD );

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int, int > pi;
typedef vector < int > vi;

int n,m,d;
char a[2010];
char b[2010];
char c[2010];

ll mod = 1000000007;
ll dp[2010][2010][2];

ll f(int rem,int idx,int flag){
    if(dp[rem][idx][flag]!=-1)return dp[rem][idx][flag];
    if(idx==n){
        if(rem==0)return 1;
        else return 0;
    }
    ll res = 0;
    if(idx%2){
        if(flag){
            if(d>c[idx])res = 0;
            else {
                if(d==c[idx])
                    res = f((rem*10 + d)%m,idx+1,1);
                else
                    res = f((rem*10 + d)%m,idx+1,0);
            }
        }
        else {
            res = f((rem*10 + d)%m,idx+1,0);
        }
    }else{
        if(flag){
            for(int i=0;i<c[idx];i++){
                if(i!=d){
                    res += f((rem*10 + i)%m,idx+1,0);
                    res %= mod;
                }
            }
            if(c[idx]!=d)
                res += f((rem*10 + c[idx])%m,idx+1,1);
        }
        else{
            for(int i=0;i<=9;i++){
                if(i!=d){
                    res += f((rem*10 + i)%m,idx+1,0);
                    res %= mod;
                }
            }
        }
    }
    res %= mod;
    return dp[rem][idx][flag] = res;
}

bool check(){
    ll rem = 0;
    for(int i=0;i<n;i+=2){
        if(a[i]==d)return 0;
    }
    for(int i=1;i<n;i+=2){
        if(a[i]!=d)return 0;
    }
    for(int i=0;i<n;i++){
        rem = (rem*10 + a[i])%m;
    }
    if(rem)return 0;
    return 1;
}

int main(){
    cin>>m>>d;
    scanf("%s",&a);
    scanf("%s",&b);
    n = strlen(a);
    for(int i=0;i<n;i++)b[i] -= '0';
    for(int i=0;i<n;i++)a[i] -= '0';
    for(int i=0;i<n;i++)c[i] = b[i];
    memset(dp,-1,sizeof dp);
    ll res = f(0,0,1);
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)c[i] = a[i];
    res -= f(0,0,1);
    res = (res + mod)%mod;
    if(check())res++;
    res %= mod;
    cout<<res<<endl;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int, int > pi;
typedef vector < int > vi;

int n,m,d;
char a[2010];
char b[2010];
char c[2010];

ll mod = 1000000007;
ll dp[2010][2010][2];

ll f(int rem,int idx,int flag){
    if(dp[rem][idx][flag]!=-1)return dp[rem][idx][flag];
    if(idx==n){
        if(rem==0)return 1;
        else return 0;
    }
    ll res = 0;
    if(idx%2){
        if(flag){
            if(d>c[idx])res = 0;
            else {
                if(d==c[idx])
                    res = f((rem*10 + d)%m,idx+1,1);
                else
                    res = f((rem*10 + d)%m,idx+1,0);
            }
        }
        else {
            res = f((rem*10 + d)%m,idx+1,0);
        }
    }else{
        if(flag){
            for(int i=0;i<c[idx];i++){
                if(i!=d){
                    res += f((rem*10 + i)%m,idx+1,0);
                    res %= mod;
                }
            }
            res += f((rem*10 + c[idx])%m,idx+1,1);
        }
        else{
            for(int i=0;i<=9;i++){
                if(i!=d){
                    res += f((rem*10 + i)%m,idx+1,0);
                    res %= mod;
                }
            }
        }
    }
    res %= mod;
    return dp[rem][idx][flag] = res;
}

bool check(){
    ll rem = 0;
    for(int i=0;i<n;i+=2){
        if(a[i]==d)return 0;
    }
    for(int i=1;i<n;i+=2){
        if(a[i]!=d)return 0;
    }
    for(int i=0;i<n;i++){
        rem = (rem*10 + a[i])%m;
    }
    if(rem)return 0;
    return 1;
}

int main(){
    cin>>m>>d;
    scanf("%s",&a);
    scanf("%s",&b);
    n = strlen(a);
    for(int i=0;i<n;i++)b[i] -= '0';
    for(int i=0;i<n;i++)a[i] -= '0';
    strcpy(c,b);
    memset(dp,-1,sizeof dp);
    ll res = f(0,0,1);
    memset(dp,-1,sizeof dp);
    strcpy(c,a);
    res -= f(0,0,1);
    res = (res + mod)%mod;
    if(check())res++;
    cout<<res<<endl;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int, int > pi;
typedef vector < int > vi;

int n,m,d;
char a[2010];
char b[2010];
char c[2010];

ll mod = 1000000007;
ll dp[2010][2010][2];

ll f(int rem,int idx,int flag){
    if(dp[rem][idx][flag]!=-1)return dp[rem][idx][flag];
    if(idx==n){
        if(rem==0)return 1;
        else return 0;
    }
    ll res = 0;
    if(idx%2){
        if(flag){
            if(d>c[idx])res = 0;
            else {
                if(d==c[idx])
                    res = f((rem*10 + d)%m,idx+1,1);
                else
                    res = f((rem*10 + d)%m,idx+1,0);
            }
        }
        else {
            res = f((rem*10 + d)%m,idx+1,0);
        }
    }else{
        if(flag){
            for(int i=0;i<c[idx];i++){
                if(i!=d){
                    res += f((rem*10 + i)%m,idx+1,0);
                    res %= mod;
                }
            }
            if(c[idx]!=d)
                res += f((rem*10 + c[idx])%m,idx+1,1);
        }
        else{
            for(int i=0;i<=9;i++){
                if(i!=d){
                    res += f((rem*10 + i)%m,idx+1,0);
                    res %= mod;
                }
            }
        }
    }
    res %= mod;
    return dp[rem][idx][flag] = res;
}

bool check(){
    ll rem = 0;
    for(int i=0;i<n;i+=2){
        if(a[i]==d)return 0;
    }
    for(int i=1;i<n;i+=2){
        if(a[i]!=d)return 0;
    }
    for(int i=0;i<n;i++){
        rem = (rem*10 + a[i])%m;
    }
    if(rem)return 0;
    return 1;
}

int main(){
    cin>>m>>d;
    scanf("%s",&a);
    scanf("%s",&b);
    n = strlen(a);
    for(int i=0;i<n;i++)b[i] -= '0';
    for(int i=0;i<n;i++)a[i] -= '0';
    strcpy(c,b);
    memset(dp,-1,sizeof dp);
    ll res = f(0,0,1);
    memset(dp,-1,sizeof dp);
    strcpy(c,a);
    res -= f(0,0,1);
    res = (res + mod)%mod;
    if(check())res++;
    res %= mod;
    cout<<res<<endl;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int, int > pi;
typedef vector < int > vi;

int n,m,d;
char a[2010];
char b[2010];
char c[2010];

ll mod = 1000000007;
ll dp[2010][2010][2];

ll f(int rem,int idx,int flag){
    if(dp[rem][idx][flag]!=-1)return dp[rem][idx][flag];
    if(idx==n){
        if(rem==0)return 1;
        else return 0;
    }
    ll res = 0;
    if(idx%2){
        if(flag){
            if(d>c[idx])res = 0;
            else {
                if(d==c[idx])
                    res = f((rem*10 + d)%m,idx+1,1);
                else
                    res = f((rem*10 + d)%m,idx+1,0);
            }
        }
        else {
            res = f((rem*10 + d)%m,idx+1,0);
        }
    }else{
        if(flag){
            for(int i=0;i<c[idx];i++){
                if(i!=d){
                    res += f((rem*10 + i)%m,idx+1,0);
                    res %= mod;
                }
            }
            if(c[idx]!=d)
                res += f((rem*10 + c[idx])%m,idx+1,1);
        }
        else{
            for(int i=0;i<=9;i++){
                if(i!=d){
                    res += f((rem*10 + i)%m,idx+1,0);
                    res %= mod;
                }
            }
        }
    }
    res %= mod;
    return dp[rem][idx][flag] = res;
}

bool check(){
    ll rem = 0;
    for(int i=0;i<n;i+=2){
        if(a[i]==d)return 0;
    }
    for(int i=1;i<n;i+=2){
        if(a[i]!=d)return 0;
    }
    for(int i=0;i<n;i++){
        rem = (rem*10 + a[i])%m;
    }
    if(rem)return 0;
    return 1;
}

int main(){
    cin>>m>>d;
    scanf("%s",&a);
    scanf("%s",&b);
    n = strlen(a);
    for(int i=0;i<n;i++)b[i] -= '0';
    for(int i=0;i<n;i++)a[i] -= '0';
    strcpy(c,b);
    memset(dp,-1,sizeof dp);
    ll res = f(0,0,1);
    memset(dp,-1,sizeof dp);
    strcpy(c,a);
    res -= f(0,0,1);
    res = (res + mod)%mod;
    if(check())res++;
    cout<<res<<endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
//#include <thread>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forn1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y1 __y1
#define sqr(x) (x) * (x)

typedef long long li;
typedef long double ld;

const int INF = (int)(1e9);
const ld eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
const li MOD = 1e9 + 7;

li m, d;
string a, b;
li z[2222][2222][2];

inline li mod(li a, li b) {
	return (((a % MOD + b % MOD) % MOD) + MOD) % MOD;
}

li calc(string n) {
	for (int i = 0; i < n.size() + 1; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < 2; k++)
				z[i][j][k] = 0;
	z[0][0][1] = 1;
	for (int i = 0; i < n.size(); i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < 2; k++) {
				for (int p = 0; p < 10; p++) {
					if (i == 0 && p == 0)
						continue;
					if (p == d && i % 2 == 0)
						continue;
					if (p != d && i % 2 != 0)
						continue;
					if (k == 1 && p > n[i] - '0')
						break;
					li ni = i + 1,
						nj = (10 * j + p) % m,
						nk = k && (p == n[i] - '0');
					z[ni][nj][nk] = mod(z[ni][nj][nk], z[i][j][k]);
				}
			}
		}
	}
	return mod(z[n.size()][0][0], z[n.size()][0][1]);
}

li g(string s) {
	li tek = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == '0' + d)
			return 0;
		if (i % 2 != 0 && s[i] != '0' + d)
			return 0;
		tek = (10 * tek + (s[i] - '0')) % m;

	}
	return (tek != 0 ? 0 : 1);
}

int main() {
	srand(int(time(NULL)));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	cin >> m >> d;
	cin >> a >> b;
	cout << calc(b) - calc(a) + g(a) << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
//#include <thread>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forn1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y1 __y1
#define sqr(x) (x) * (x)

typedef long long li;
typedef long double ld;

const int INF = (int)(1e9);
const ld eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
const li MOD = 1e9 + 7;

li m, d;
string a, b;
li z[2222][2222][2];

inline li mod(li a, li b) {
	return (a % MOD + b % MOD + MOD) % MOD;
}

li calc(string n) {
	for (int i = 0; i < n.size() + 1; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < 2; k++)
				z[i][j][k] = 0;
	z[0][0][1] = 1;
	for (int i = 0; i < n.size(); i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < 2; k++) {
				for (int p = 0; p < 10; p++) {
					if (i == 0 && p == 0)
						continue;
					if (p == d && i % 2 == 0)
						continue;
					if (p != d && i % 2 != 0)
						continue;
					if (k == 1 && p > n[i] - '0')
						break;
					li ni = i + 1,
						nj = (10 * j + p) % m,
						nk = k && (p == n[i] - '0');
					z[ni][nj][nk] = mod(z[ni][nj][nk], z[i][j][k]);
				}
			}
		}
	}
	return mod(z[n.size()][0][0], z[n.size()][0][1]);
}

li g(string s) {
	li tek = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == '0' + d)
			return 0;
		if (i % 2 != 0 && s[i] != '0' + d)
			return 0;
		tek = (10 * tek + (s[i] - '0')) % m;

	}
	return (tek != 0 ? 0 : 1);
}

int main() {
	srand(int(time(NULL)));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	cin >> m >> d;
	cin >> a >> b;
	cout << calc(b) - calc(a) + g(a) << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
//#include <thread>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forn1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y1 __y1
#define sqr(x) (x) * (x)

typedef long long li;
typedef long double ld;

const int INF = (int)(1e9);
const ld eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
const int MOD = 1e9 + 7;

int m, d;
string a, b;
int z[2222][2222][2];

inline int mod(int a, int b) {
	if (a + b >= MOD)
		return a + b - MOD;
	else
		return (a + b + MOD) % MOD;
}

li calc(string n) {
	for (int i = 0; i < n.size() + 1; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < 2; k++)
				z[i][j][k] = 0;
	z[0][0][1] = 1;
	for (int i = 0; i < n.size(); i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < 2; k++) {
				for (int p = 0; p < 10; p++) {
					if (p == d && i % 2 == 0)
						continue;
					if (p != d && i % 2 != 0)
						continue;
					if (k == 1 && p > n[i] - '0')
						break;
					if (i == 0 && p == 0)
						continue;
					int ni = i + 1,
						nj = (10 * j + p) % m,
						nk = k && (p == n[i] - '0');
					z[ni][nj][nk] = mod(z[ni][nj][nk], z[i][j][k]);
				}
			}
		}
	}
	return mod(z[n.size()][0][0], z[n.size()][0][1]);
}

int g(string s) {
	int tek = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == '0' + d)
			return 0;
		if (i % 2 != 0 && s[i] != '0' + d)
			return 0;
		tek = (10 * tek + (s[i] - '0')) % m;
	}
	return (tek != 0 ? 0 : 1);
}

int main() {
	srand(int(time(NULL)));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	cin >> m >> d;
	cin >> a >> b;
	cout << mod(calc(b), -calc(a) + g(a)) << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
//#include <thread>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forn1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y1 __y1
#define sqr(x) (x) * (x)

typedef long long li;
typedef long double ld;

const int INF = (int)(1e9);
const ld eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
const li MOD = 1e9 + 7;

li m, d;
string a, b;
li z[2222][2222][2];

inline li mod(li a, li b) {
	return (((a % MOD + b % MOD) % MOD) + MOD) % MOD;
}

li calc(string n) {
	for (int i = 0; i < n.size() + 1; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < 2; k++)
				z[i][j][k] = 0;
	z[0][0][1] = 1;
	for (int i = 0; i < n.size(); i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < 2; k++) {
				for (int p = 0; p < 10; p++) {
					if (i == 0 && p == 0)
						continue;
					if (p == d && i % 2 == 0)
						continue;
					if (p != d && i % 2 != 0)
						continue;
					if (k == 1 && p > n[i] - '0')
						continue;
					li ni = i + 1,
						nj = (10 * j + p) % m,
						nk = k && (p == n[i] - '0');
					z[ni][nj][nk] = mod(z[ni][nj][nk], z[i][j][k]);
				}
			}
		}
	}
	return mod(z[n.size()][0][0], z[n.size()][0][1]);
}

li g(string s) {
	li tek = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == '0' + d)
			return 0;
		if (i % 2 != 0 && s[i] != '0' + d)
			return 0;
		tek = (10 * tek + (s[i] - '0')) % m;

	}
	return (tek != 0 ? 0 : 1);
}

int main() {
	srand(int(time(NULL)));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	cin >> m >> d;
	cin >> a >> b;
	cout << calc(b) - calc(a) + g(a) << endl;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
//#include <thread>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forn1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y1 __y1
#define sqr(x) (x) * (x)

typedef long long li;
typedef long double ld;

const int INF = (int)(1e9);
const ld eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
const li MOD = 1e9 + 7;

li m, d;
string a, b;
li z[2222][2222][2];

li calc(string n) {
	for (int i = 0; i < n.size() + 1; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < 2; k++)
				z[i][j][k] = 0;
	z[0][0][1] = 1;
	for (int i = 0; i < n.size(); i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < 2; k++) {
				for (int p = 0; p < 10; p++) {
					if (p == d && i % 2 == 0)
						continue;
					if (p != d && i % 2 != 0)
						continue;
					if (k == 1 && p > n[i] - '0')
						break;
					li ni = i + 1,
						nj = (10 * j + p) % m,
						nk = k && (p == n[i] - '0');
					z[ni][nj][nk] = ((z[ni][nj][nk]) % MOD + (z[i][j][k]) % MOD) % MOD;
				}
			}
		}
	}
	return (z[n.size()][0][0] % MOD + z[n.size()][0][1] % MOD) % MOD;
}

li g(string s) {
	li tek = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == '0' + d)
			return 0;
		if (i % 2 != 0 && s[i] != '0' + d)
			return 0;
		tek = (10 * tek + (s[i] - '0')) % m;

	}
	return (tek != 0 ? 0 : 1);
}

int main() {
	srand(int(time(NULL)));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	cin >> m >> d;
	cin >> a >> b;
	cout << calc(b) - calc(a) + g(a) << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
//#include <thread>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forn1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y1 __y1
#define sqr(x) (x) * (x)

typedef long long li;
typedef long double ld;

const int INF = (int)(1e9);
const ld eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
const li MOD = 1e9 + 7;

li m, d;
string a, b;
li z[2222][2222][2];

inline li mod(li a, li b) {
	return (a % MOD + b % MOD + MOD) % MOD;
}

li calc(string n) {
	for (int i = 0; i < n.size() + 1; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < 2; k++)
				z[i][j][k] = 0;
	z[0][0][1] = 1;
	for (int i = 0; i < n.size(); i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < 2; k++) {
				for (int p = 0; p < 10; p++) {
					if (p == d && i % 2 == 0)
						continue;
					if (p != d && i % 2 != 0)
						continue;
					if (k == 1 && p > n[i] - '0')
						break;
					if (i == 0 && p == 0)
						continue;
					li ni = i + 1,
						nj = (10 * j + p) % m,
						nk = k && (p == n[i] - '0');
					z[ni][nj][nk] = mod(z[ni][nj][nk], z[i][j][k]);
				}
			}
		}
	}
	return mod(z[n.size()][0][0], z[n.size()][0][1]);
}

li g(string s) {
	li tek = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == '0' + d)
			return 0;
		if (i % 2 != 0 && s[i] != '0' + d)
			return 0;
		tek = (10 * tek + (s[i] - '0')) % m;
	}
	return (tek != 0 ? 0 : 1);
}

int main() {
	srand(int(time(NULL)));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	cin >> m >> d;
	cin >> a >> b;
	cout << calc(b) - calc(a) + g(a) << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
//#include <thread>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forn1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y1 __y1
#define sqr(x) (x) * (x)

typedef long long li;
typedef long double ld;

const int INF = (int)(1e9);
const ld eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
const li MOD = 1e9 + 7;

li m, d;
string a, b;
li z[2222][2222][2];

li mod(li a, li b) {
	return (((a % MOD + b % MOD) % MOD) + MOD) % MOD;
}

li calc(string n) {
	for (int i = 0; i < n.size() + 1; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < 2; k++)
				z[i][j][k] = 0;
	z[0][0][1] = 1;
	for (int i = 0; i < n.size(); i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < 2; k++) {
				for (int p = 0; p < 10; p++) {
					if (i == 0 && p == 0)
						continue;
					if (p == d && i % 2 == 0)
						continue;
					if (p != d && i % 2 != 0)
						continue;
					if (k == 1 && p > n[i] - '0')
						continue;
					li ni = i + 1,
						nj = (10 * j + p) % m,
						nk = k && (p == n[i] - '0');
					z[ni][nj][nk] = mod(z[ni][nj][nk], z[i][j][k]);
				}
			}
		}
	}
	return mod(z[n.size()][0][0], z[n.size()][0][1]);
}

li g(string s) {
	li tek = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == '0' + d)
			return 0;
		if (i % 2 != 0 && s[i] != '0' + d)
			return 0;
		tek = (10 * tek + (s[i] - '0')) % m;

	}
	return (tek != 0 ? 0 : 1);
}

int main() {
	srand(int(time(NULL)));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	cin >> m >> d;
	cin >> a >> b;
	cout << calc(b) - calc(a) + g(a) << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
//#include <thread>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forn1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y1 __y1
#define sqr(x) (x) * (x)

typedef long long li;
typedef long double ld;

const int INF = (int)(1e9);
const ld eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
const int MOD = 1e9 + 7;

int m, d;
string a, b;
int z[2222][2222][2];

inline int mod(int a, int b) {
	if (a + b >= MOD)
		return a + b - MOD;
	else
		return a + b;
}

li calc(string n) {
	for (int i = 0; i < n.size() + 1; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < 2; k++)
				z[i][j][k] = 0;
	z[0][0][1] = 1;
	for (int i = 0; i < n.size(); i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < 2; k++) {
				for (int p = 0; p < 10; p++) {
					if (p == d && i % 2 == 0)
						continue;
					if (p != d && i % 2 != 0)
						continue;
					if (k == 1 && p > n[i] - '0')
						break;
					if (i == 0 && p == 0)
						continue;
					int ni = i + 1,
						nj = (10 * j + p) % m,
						nk = k && (p == n[i] - '0');
					z[ni][nj][nk] = mod(z[ni][nj][nk], z[i][j][k]);
				}
			}
		}
	}
	return mod(z[n.size()][0][0], z[n.size()][0][1]);
}

int g(string s) {
	int tek = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == '0' + d)
			return 0;
		if (i % 2 != 0 && s[i] != '0' + d)
			return 0;
		tek = (10 * tek + (s[i] - '0')) % m;
	}
	return (tek != 0 ? 0 : 1);
}

int main() {
	srand(int(time(NULL)));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	cin >> m >> d;
	cin >> a >> b;
	cout << calc(b) - calc(a) + g(a) << endl;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
//#include <thread>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forn1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y1 __y1
#define sqr(x) (x) * (x)

typedef long long li;
typedef long double ld;

const int INF = (int)(1e9);
const ld eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
const li MOD = 1e9 + 7;

li m, d;
string a, b;
li z[2222][2222][2];

li calc(string n) {
	for (int i = 0; i < n.size() + 1; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < 2; k++)
				z[i][j][k] = 0;
	z[0][0][1] = 1;
	for (int i = 0; i < n.size(); i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < 2; k++) {
				for (int p = 0; p < 10; p++) {
				    if (i == 0 && p == 0)
				        continue;
					if (p == d && i % 2 == 0)
						continue;
					if (p != d && i % 2 != 0)
						continue;
					if (k == 1 && p > n[i] - '0')
						continue;
					li ni = i + 1,
						nj = (10 * j + p) % m,
						nk = k && (p == n[i] - '0');
					z[ni][nj][nk] = ((z[ni][nj][nk]) % MOD + (z[i][j][k]) % MOD) % MOD;
				}
			}
		}
	}
	return (z[n.size()][0][0] % MOD + z[n.size()][0][1] % MOD) % MOD;
}

li g(string s) {
	li tek = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == '0' + d)
			return 0;
		if (i % 2 != 0 && s[i] != '0' + d)
			return 0;
		tek = (10 * tek + (s[i] - '0')) % m;

	}
	return (tek != 0 ? 0 : 1);
}

int main() {
	srand(int(time(NULL)));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	cin >> m >> d;
	cin >> a >> b;
	cout << calc(b) - calc(a) + g(a) << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
//#include <thread>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forn1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y1 __y1
#define sqr(x) (x) * (x)

typedef long long li;
typedef long double ld;

const int INF = (int)(1e9);
const ld eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
const li MOD = 1e9 + 7;

li m, d;
string a, b;
li z[2222][2222][2];

inline li mod(li a, li b) {
	return (a % MOD + b % MOD + MOD) % MOD;
}

li calc(string n) {
	for (int i = 0; i < n.size() + 1; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < 2; k++)
				z[i][j][k] = 0;
	z[0][0][1] = 1;
	for (int i = 0; i < n.size(); i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < 2; k++) {
				for (int p = 0; p < 10; p++) {
					/*if (i == 0 && p == 0)
						continue;*/
					if (p == d && i % 2 == 0)
						continue;
					if (p != d && i % 2 != 0)
						continue;
					if (k == 1 && p > n[i] - '0')
						break;
					li ni = i + 1,
						nj = (10 * j + p) % m,
						nk = k && (p == n[i] - '0');
					z[ni][nj][nk] = mod(z[ni][nj][nk], z[i][j][k]);
				}
			}
		}
	}
	return mod(z[n.size()][0][0], z[n.size()][0][1]);
}

li g(string s) {
	li tek = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == '0' + d)
			return 0;
		if (i % 2 != 0 && s[i] != '0' + d)
			return 0;
		tek = (10 * tek + (s[i] - '0')) % m;

	}
	return (tek != 0 ? 0 : 1);
}

int main() {
	srand(int(time(NULL)));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	cin >> m >> d;
	cin >> a >> b;
	cout << calc(b) - calc(a) + g(a) << endl;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define maxn 2222
#define LL __int64
const LL MOD = 1e9+7;

int m,d,len;
char a[maxn],b[maxn];
int num[maxn];
LL dp[maxn][maxn];

LL dfs(int pos,int yushu,bool yes){
    if(pos==len) return yushu==0;
    if(!yes&&dp[pos][yushu]!=-1) return dp[pos][yushu];
    LL ans=0;
    int End=yes?num[pos]:9;
    for(int i=0;i<=End;i++){
        if(pos%2==0&&i==d) continue;
        if(pos%2==1&&i!=d) continue;
        ans+=dfs(pos+1,(yushu*10+i)%m,yes&&(i==End));
    }
    if(!yes) dp[pos][yushu]=ans;
    return ans;
}

LL Count(char str[]){
    for(int i=0;i<len;i++) num[i]=str[i]-'0';
    return dfs(0,0,1);
}

LL is_judge(char a[]){
    int yushu=0;
    for(int i=0;i<len;i++){
        if((i&1)&&(a[i]-'0')!=d) return 0;
        if((i&1)==0&&(a[i]-'0')==d) return 0;
        yushu=yushu*10+(a[i]-'0');
        yushu%=m;
    }
    return yushu==0?1:0;
}

int main(){
    memset(dp,-1,sizeof(dp));
    while(scanf("%d%d",&m,&d)!=EOF){
        scanf("%s%s",a,b);
        len=strlen(a);
        printf("%I64d\n",(Count(b)-Count(a)+is_judge(a))%MOD);
    }

    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define maxn 2222
#define LL __int64
const LL MOD = 1e9+7;

int m,d,len;
int bit[maxn];
LL dp[maxn][maxn];

LL dfs(int pos,int yushu,bool yes){
    if(pos==len) return yushu==0;
    if(!yes&&dp[pos][yushu]!=-1) return dp[pos][yushu];
    LL ans=0;
    int End=yes?bit[pos]:9;
    for(int i=0;i<=End;i++){
        if(pos%2==0&&i==d) continue;
        if(pos%2==1&&i!=d) continue;
        ans=(ans+dfs(pos+1,(yushu*10+i)%m,yes&&(i==End)))%MOD;
    }
    if(!yes) dp[pos][yushu]=ans;
    return ans;
}

LL Count(char str[]){
    for(int i=0;i<len;i++) bit[i]=str[i]-'0';
    return dfs(0,0,1);
}

LL is_judge(char str[]){
    int yushu=0;
    for(int i=0;i<len;i++){
        int v=str[i]-'0';
        if((i&1)&&v!=d) return 0;
        if((i&1)==0&&v==d) return 0;
        yushu=yushu*10+v;
        yushu%=m;
    }
    return yushu==0?1:0;
}

int main(){
    memset(dp,-1,sizeof(dp));
    while(scanf("%d%d",&m,&d)!=EOF){
        char a[maxn],b[maxn];
        scanf("%s%s",a,b);
        len=strlen(a);
        printf("%I64d\n",(Count(b)-Count(a)+is_judge(a))%MOD);
    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define maxn 2333
#define LL long long
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;

char a[2333],b[2333];
LL dp[maxn][maxn][3];
int m,d,len;

LL dfs(int high,int pos,int md){
    if(pos==len) return md==0;
    if(dp[pos][md][high%3]!=-1) return dp[pos][md][high%3];
    LL ans=0;
    int st,en;
    st=(high==0||high==3)?a[pos]-'0':0;
    en=(high==1||high==3)?b[pos]-'0':9;
    int nhigh;
    if(pos&1){
        for(int i=st;i<=en;i++){
            if(i==d) continue;
            if(high==3&&st==en) nhigh=3;
            else if((high==0||high==3)&&i==st) nhigh=0;
            else if((high==1||high==3)&&i==en) nhigh=1;
            else nhigh=2;
            ans=(ans+dfs(nhigh,pos+1,(md*10+i)%m))%MOD;
        }
    }
    else if(st<=d&&d<=en){
        if(high=3&&st==en) nhigh=3;
        else if((high==0||high==3)&&st==d) nhigh=0;
        else if((high==1||high==3)&&en==d) nhigh=1;
        else nhigh=2;
        ans=(ans+dfs(nhigh,pos+1,(md*10+d)%m))%MOD;
    }
    dp[pos][md][high%3]=ans;
    return ans;
}

int main(){
    scanf("%d%d%s%s",&m,&d,a+1,b+1);
    memset(dp,-1,sizeof(dp));
    len = strlen(a+1)+1;
    printf("%lld\n",dfs(3,1,0));

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define maxn 2333
#define LL long long
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;

char a[2333],b[2333];
LL dp[maxn][maxn][3];
int m,d,len;

LL dfs(int high,int pos,int md){
    if(pos==len) return md==0;
    if(dp[pos][md][high%3]!=0) return dp[pos][md][high%3];
    LL ans=0;
    int st,en;
    st=(high==0||high==3)?a[pos]-'0':0;
    en=(high==1||high==3)?a[pos]-'0':9;
    int nhigh;
    if(pos&1){
        for(int i=st;i<=en;i++){
            if(i==d) continue;
            if(high==3&&st==en) nhigh=3;
            else if((high==0||high==3)&&i==st) nhigh=0;
            else if((high==1||high==3)&&i==en) nhigh=1;
            else nhigh=2;
            ans=(ans+dfs(nhigh,pos+1,(md*10+i)%m))%MOD;
        }
    }
    else{
        if(high=3&&st==en) nhigh=3;
        else if((high==0||high==3)&&st==d) nhigh=0;
        else if((high==1||high==3)&&en==d) nhigh=1;
        else nhigh=2;
        ans=(ans+dfs(nhigh,pos+1,(md*10+d)%m))%MOD;
    }
    dp[pos][md][high%3]=ans;
    return ans;
}

int main(){
    scanf("%d%d%s%s",&m,&d,a+1,b+1);
    memset(dp,0,sizeof(dp));
    len = strlen(a+1)+1;
    printf("%lld\n",dfs(3,1,0));

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define maxn 2333
#define LL long long
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;

char a[2333],b[2333];
LL dp[maxn][maxn][3];
int m,d,len;
/*
29 0
1649127
6241670
*/
LL dfs(int high,int pos,int md){
    if(pos==len) return md==0;
    if(dp[pos][md][high%3]!=-1) return dp[pos][md][high%3];
    LL ans=0;
    int st,en;
    st=(high==0||high==3)?a[pos]-'0':0;
    en=(high==1||high==3)?b[pos]-'0':9;
    int nhigh;
    if(pos&1){
        for(int i=st;i<=en;i++){
            if(i==d) continue;
            if(high==3&&st==en) nhigh=3;
            else if((high==0||high==3)&&i==st) nhigh=0;
            else if((high==1||high==3)&&i==en) nhigh=1;
            else nhigh=2;
            ans=(ans+dfs(nhigh,pos+1,(md*10+i)%m))%MOD;
        }
    }
    else if(st<=d&&d<=en){
        if(high==3&&st==en) nhigh=3;
        else if((high==0||high==3)&&st==d) nhigh=0;
        else if((high==1||high==3)&&en==d) nhigh=1;
        else nhigh=2;
        ans=(ans+dfs(nhigh,pos+1,(md*10+d)%m))%MOD;
    }
    dp[pos][md][high%3]=ans;
    return ans;
}

int main(){
    scanf("%d%d%s%s",&m,&d,a+1,b+1);
    memset(dp,-1,sizeof(dp));
    len = strlen(a+1)+1;
    printf("%lld\n",dfs(3,1,0));

    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define maxn 2222
#define LL __int64
const LL MOD = 1e9+7;

int m,d,len;
int num[maxn];
LL dp[maxn][maxn];

LL dfs(int pos,int yushu,bool yes){
    if(pos==len) return yushu==0;
    if(!yes&&dp[pos][yushu]!=-1) return dp[pos][yushu];
    LL ans=0;
    int End=yes?num[pos]:9;
    for(int i=0;i<=End;i++){
        if(pos%2==0&&i==d) continue;
        if(pos%2==1&&i!=d) continue;
        ans+=dfs(pos+1,(yushu*10+i)%m,yes&&(i==End));
    }
    if(!yes) dp[pos][yushu]=ans;
    return ans;
}

LL Count(char str[]){
    for(int i=0;i<len;i++) num[i]=str[i]-'0';
    return dfs(0,0,1);
}

LL is_judge(char str[]){
    int yushu=0;
    for(int i=0;i<len;i++){
        int v=str[i]-'0';
        if((i&1)&&v!=d) return 0;
        if((i&1)==0&&v==d) return 0;
        yushu=yushu*10+v;
        yushu%=m;
    }
    return yushu==0?1:0;
}

int main(){
    memset(dp,-1,sizeof(dp));
    while(scanf("%d%d",&m,&d)!=EOF){
        char a[maxn],b[maxn];
        scanf("%s%s",a,b);
        len=strlen(a);
        printf("%I64d\n",(Count(b)-Count(a)+is_judge(a))%MOD);
    }

    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define maxn 2222
#define LL __int64
const LL MOD = 1e9+7;

int m,d,len;
char a[maxn],b[maxn];
int num[maxn];
LL dp[maxn][maxn];

LL dfs(int pos,int yushu,bool yes){
    if(pos==len) return yushu==0;
    if(!yes&&dp[pos][yushu]!=-1) return dp[pos][yushu];
    LL ans=0;
    int End=yes?num[pos]:9;
    for(int i=0;i<=End;i++){
        if(pos%2==0&&i==d) continue;
        if(pos%2==1&&i!=d) continue;
        ans+=dfs(pos+1,(yushu*10+i)%m,yes&&(i==End));
    }
    if(!yes) dp[pos][yushu]=ans;
    return ans;
}

LL Count(char str[]){
    len=strlen(str);
    for(int i=0;i<len;i++) num[i]=str[i]-'0';
    return dfs(0,0,1);
}

LL is_judge(char a[]){
    int yushu=0;
    for(int i=0;a[i]!='\0';i++){
        if((i&1)&&(a[i]-'0')!=d) return 0;
        if((i&1)==0&&(a[i]-'0')==d) return 0;
        yushu=yushu*10+(a[i]-'0');
        yushu%=m;
    }
    return yushu==0?1:0;
}

int main(){
    memset(dp,-1,sizeof(dp));
    while(scanf("%d%d",&m,&d)!=EOF){
        scanf("%s%s",a,b);
        printf("%I64d\n",(Count(b)-Count(a)+is_judge(a))%MOD);
    }

    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define maxn 2222
#define LL __int64
const LL MOD = 1e9+7;

int m,d,len;
int bit[maxn];
LL dp[maxn][maxn];

LL dfs(int pos,int yushu,bool yes){
    if(pos==len) return yushu==0;
    if(!yes&&dp[pos][yushu]!=-1) return dp[pos][yushu];
    LL ans=0;
    int End=yes?bit[pos]:9;
    for(int i=0;i<=End;i++){
        if(pos%2==0&&i==d) continue;
        if(pos%2==1&&i!=d) continue;
        ans=(ans+dfs(pos+1,(yushu*10+i)%m,yes&&(i==End)))%MOD;
    }
    if(!yes) dp[pos][yushu]=ans;
    return ans;
}

LL Count(char str[]){
    for(int i=0;i<len;i++) bit[i]=str[i]-'0';
    return dfs(0,0,1);
}

LL is_judge(char str[]){
    int yushu=0;
    for(int i=0;i<len;i++){
        int v=str[i]-'0';
        if((i&1)&&v!=d) return 0;
        if((i&1)==0&&v==d) return 0;
        yushu=yushu*10+v;
        yushu%=m;
    }
    return yushu==0?1:0;
}

int main(){
    memset(dp,-1,sizeof(dp));
    while(scanf("%d%d",&m,&d)!=EOF){
        char a[maxn],b[maxn];
        scanf("%s%s",a,b);
        len=strlen(a);
        printf("%I64d\n",(Count(b)-Count(a)+is_judge(a)+MOD)%MOD);
    }

    return 0;
}


//84104971101048411497 - Can you guess what does this mean?
using namespace std;
#include <bits/stdc++.h>
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i,  r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define fordit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long
#define maxN 2005
#define MOD 1000000007

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int m, d, a, b;

bool Check(int a) {
    if (a%m != 0) return false;
    stringstream ss;
    ss << a;
    string s = ss.str();
    int n = s.length();
    fto(i, 0, n-1) {
        if (i%2 == 0 && s[i] == d+'0') return false;
        else if (i%2 == 1 && s[i] != d+'0') return false;
    }
    return true;
}

int main () {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE

    scanf("%d%d", &m, &d);
    cin >> a >> b;

    int ans = 0;
    fto(i, a, b) {
        if (Check(i)) ++ans;
    }
    cout << ans;

    return 0;
}


//84104971101048411497 - Can you guess what does this mean?
using namespace std;
#include <bits/stdc++.h>
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i,  r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define fordit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long
#define maxN 2005
#define MOD 1000000007

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int m, d, n, f[maxN][maxN][2];
string a, b;

int DP(string &s, int i, int r, bool low) {
    if (i == n) return (r == 0);
    if (f[i][r][low] != -1) return f[i][r][low];

    int res = 0, a = 0, b = (low) ? 9 : (s[i]-'0');
    if (i%2 == 1) a = d, b = min(b, d);
    fto(x, a, b) {
        if (i%2 == 1 || x != d) res = (res + DP(s, i+1, (r*10+x)%m, (low)|(x < b)))%MOD;
    }

    return (f[i][r][low] = res);
}

int Solve(string &s) {
    fto(i, 0, n-1)
        fto(r, 0, m-1)
            fto(low, 0, 1) f[i][r][low] = -1;
    return DP(s, 0, 0, 0);
}

int main () {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE

    scanf("%d%d", &m, &d);
    cin >> a >> b;
    n = a.length();

    int mem = 1;
    fdto(i, n-1, 0) {
        a[i] -= mem;
        if (a[i] < '0') {
            a[i] += 10;
            mem = 1;
        }
        else mem = 0;
    }
//    debug(Solve(b));
//    debug(Solve(a));

    cout << (Solve(b)-Solve(a)+MOD)%MOD;

    return 0;
}


//84104971101048411497 - Can you guess what does this mean?
using namespace std;
#include <bits/stdc++.h>
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i,  r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define fordit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long
#define maxN 2005
#define MOD 1000000007

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int m, d, n, f[maxN][maxN][2];
string a, b;

int DP(string &s, int i, int r, bool low) {
    if (i == n) return (r == 0);
    if (f[i][r][low] != -1) return f[i][r][low];

    int res = 0, a = (i == 0) ? 1 : 0, b = (low) ? 9 : (s[i]-'0');
    if (i%2 == 1) a = max(a, d), b = min(b, d);
    fto(x, a, b) {
        if (i%2 == 1 || x != d) res = (res + DP(s, i+1, (r*10+x)%m, (low)|(x < s[i]-'0')))%MOD;
    }

    return (f[i][r][low] = res);
}

int Solve(string &s) {
    fto(i, 0, n-1)
        fto(r, 0, m-1)
            fto(low, 0, 1) f[i][r][low] = -1;
    return DP(s, 0, 0, 0);
}

int main () {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE

    scanf("%d%d", &m, &d);
    cin >> a >> b;
    n = a.length();

    int mem = 1;
    fdto(i, n-1, 0) {
        a[i] -= mem;
        if (a[i] < '0') {
            a[i] += 10;
            mem = 1;
        }
        else mem = 0;
    }
//    debug(Solve(b));
//    debug(Solve(a));
    if (a[0] == 0) cout << Solve(b);
    else cout << (Solve(b)-Solve(a)+MOD)%MOD;

    return 0;
}


//84104971101048411497 - Can you guess what does this mean?
using namespace std;
#include <bits/stdc++.h>
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i,  r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define fordit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long
#define maxN 2005
#define MOD 1000000007

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int m, d, n, f[maxN][maxN][2];
string a, b;

int DP(string &s, int i, int r, bool low) {
    if (i == n) return (r == 0);
    if (f[i][r][low] != -1) return f[i][r][low];

    int res = 0, a = 0, b = (low) ? 9 : (s[i]-'0');
    if (i%2 == 1) a = d, b = d;
    fto(x, a, b) {
        if (i%2 == 1 || x != d) res = (res + DP(s, i+1, (r*10+x)%m, (low)|(x < b)))%MOD;
    }

    return (f[i][r][low] = res);
}

int Solve(string &s) {
    fto(i, 0, n-1)
        fto(r, 0, m-1)
            fto(low, 0, 1) f[i][r][low] = -1;
    return DP(s, 0, 0, 0);
}

int main () {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE

    scanf("%d%d", &m, &d);
    cin >> a >> b;
    n = a.length();

    int mem = 1;
    fdto(i, n-1, 0) {
        a[i] -= mem;
        if (a[i] < '0') {
            a[i] += 10;
            mem = 1;
        }
        else mem = 0;
    }
    debug(b);
    debug(a);

    cout << (Solve(b)-Solve(a)+MOD)%MOD;

    return 0;
}


//84104971101048411497 - Can you guess what does this mean?
using namespace std;
#include <bits/stdc++.h>
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i,  r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define fordit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long
#define maxN 2005
#define MOD 1000000007

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int m, d, n, f[maxN][maxN][2];
string a, b;

int DP(string &s, int i, int r, bool low) {
    if (i == n) return (r == 0);
    if (f[i][r][low] != -1) return f[i][r][low];

    int res = 0, a = 0, b = (low) ? 9 : (s[i]-'0');
    if (i%2 == 1) a = d, b = d;
    fto(x, a, b) {
        if (i%2 == 1 || x != d) res = (res + DP(s, i+1, (r*10+x)%m, (low)|(x < b)))%MOD;
    }

    return (f[i][r][low] = res);
}

int Solve(string &s) {
    fto(i, 0, n-1)
        fto(r, 0, m-1)
            fto(low, 0, 1) f[i][r][low] = -1;
    return DP(s, 0, 0, 0);
}

int main () {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE

    scanf("%d%d", &m, &d);
    cin >> a >> b;
    n = a.length();

    int mem = 1;
    fdto(i, n-1, 0) {
        a[i] -= mem;
        if (a[i] < '0') {
            a[i] += 10;
            mem = 1;
        }
        else mem = 0;
    }
//    debug(b);
//    debug(a);

    cout << (Solve(b)-Solve(a)+MOD)%MOD;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2005;
const int mod=1e9+7;
int m,d;
char a[N],b[N];
ll f[N][N];
int bit[N];
int len;
ll dfs(int pos,int pre,bool lim)
{
    if(pos==len)return pre==0;
    if(!lim&&f[pos][pre]!=-1)return f[pos][pre];
    ll ans=0;
    int n=lim?bit[pos]:9;
    for(int i=0;i<=n;i++){
        if(pos&1&&i!=d)continue;
        if(!(pos&1)&&i==d)continue;
        ans=(ans+dfs(pos+1,(pre*10+i)%m,lim&&i==n))%mod;
    }
    if(!lim)f[pos][pre]=ans;
    return ans;
}
ll judge(char *s)
{
    int ok=0;
    for(int i=0;i<len;i++){
        int t=s[i]-'0';
        ok=(ok*10+t)%m;
        if(!i&&t==d)return false;
        if(i&&t!=d)return false;
    }
    return ok==0;
}
ll solve(char *s)
{
    len=strlen(s);
    for(int i=0;i<len;i++)bit[i]=s[i]-'0';
    return dfs(0,0,1);
}
int main()
{
    scanf("%d%d",&m,&d);
    scanf("%s%s",a,b);
    memset(f,-1,sizeof(f));
    cout<<solve(b)-solve(a)+judge(a)<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=2009;
int f[N][N],bit[N];
char a[N],b[N];
int m,d,len;
int dfs(int pos,int pre,bool lim)
{
    if(pos==len+1)return pre==0;
    if(!lim&&f[pos][pre]!=-1)return f[pos][pre];
    int num=lim?bit[pos]:9;
    int ans=0;
    for(int i=0;i<=num;i++){
        if((pos&1)&&i==d)continue;
        if(!(pos&1)&&i!=d)continue;
        ans=(ans+dfs(pos+1,(pre*10+i)%m,lim&&i==num))%mod;
    }
    if(!lim)f[pos][pre]=ans;
    return ans;
}
int solve(const char *s)
{
    len=strlen(s);
    for(int i=0;i<len;i++)bit[i+1]=s[i]-'0';
    return dfs(1,0,1);
}
int judge(const char *s)
{
    len-strlen(s);
    int pre=0;
    for(int i=0;i<len;i++){
        pre=(pre*10+s[i]-'0')%m;
        if(i&1&&(s[i]-'0'!=d))return 0;
        if(!(i&1)&&s[i]-'0'==d)return 0;
    }
    return pre==0;
}
int main()
{
    //freopen("f.txt","r",stdin);
    memset(f,-1,sizeof(f));
    scanf("%d%d",&m,&d);
    scanf("%s%s",a,b);
    printf("%d\n",(solve(b)-solve(a)+judge(a)+mod)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2005;
const int mod=1e9+7;
int m,d;
char a[N],b[N];
ll f[N][N];
int bit[N];
int len;
ll dfs(int pos,int pre,bool lim)
{
    if(pos==len)return pre==0;
    if(!lim&&f[pos][pre]!=-1)return f[pos][pre];
    ll ans=0;
    int n=lim?bit[pos]:9;
    for(int i=0;i<=n;i++){
        if(pos&1&&i!=d)continue;
        if(!(pos&1)&&i==d)continue;
        ans=(ans+dfs(pos+1,(pre*10+i)%m,lim&&i==n)%mod)%mod;
    }
    if(!lim)f[pos][pre]=ans;
    return ans;
}
bool judge(char *s)
{
    int ok=0;
    for(int i=0;i<len;i++){
        int t=s[i]-'0';
        ok=(ok*10+t)%m;
        if(!(i&1)&&t==d)return false;
        if((i&1)&&t!=d)return false;
    }
    return ok==0;
}
ll solve(char *s)
{
    len=strlen(s);
    for(int i=0;i<len;i++)bit[i]=s[i]-'0';
    return dfs(0,0,1);
}
int main()
{
    scanf("%d%d",&m,&d);
    scanf("%s%s",a,b);
    memset(f,-1,sizeof(f));
    cout<<(solve(b)-solve(a)+judge(a)+mod)%mod<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2005;
const int mod=1e9+7;
int m,d;
char a[N],b[N];
ll f[N][N];
int bit[N];
int len;
ll dfs(int pos,int pre,bool lim)
{
    if(pos==len)return pre==0;
    if(!lim&&f[pos][pre]!=-1)return f[pos][pre];
    ll ans=0;
    int n=lim?bit[pos]:9;
    for(int i=0;i<=n;i++){
        if(pos&1&&i!=d)continue;
        if(!(pos&1)&&i==d)continue;
        ans=(ans+dfs(pos+1,(pre*10+i)%m,lim&&i==n)%mod)%mod;
    }
    if(!lim)f[pos][pre]=ans;
    return ans;
}
bool judge(char *s)
{
    int ok=0;
    for(int i=0;i<len;i++){
        int t=s[i]-'0';
        ok=(ok*10+t)%m;
        if(!i&&t==d)return false;
        if(i&&t!=d)return false;
    }
    return ok==0;
}
ll solve(char *s)
{
    len=strlen(s);
    for(int i=0;i<len;i++)bit[i]=s[i]-'0';
    return dfs(0,0,1);
}
int main()
{
    scanf("%d%d",&m,&d);
    scanf("%s%s",a,b);
    memset(f,-1,sizeof(f));
    cout<<(solve(b)-solve(a)+judge(a)+mod)%mod<<endl;
}


#include<bits/stdc++.h>
#define eps 1e-6
#define LL long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;

const int MOD = 1e9+7;
int m, d, len;
char a[3000], b[3000];
LL dp[2500][2500][2];

int pow_mod(int a, int n)
{
	if (n == 0)
		return 1 % m;
	int ans = pow_mod(a, n/2);
	ans = (LL)ans * ans % m;
	if (n&1)
		ans = (LL)ans * a % m;
	return ans;
}

int cal_mod(int pos, int mod, int digit)
{
	return ((LL)digit*pow_mod(10, len-pos) + mod) % m;
}

LL dfs(int pos, int mod, bool appear, bool same, char* s)
{
	if (!same && (dp[pos][mod][appear] != -1))
		return dp[pos][mod][appear];
	if (pos > len) {
		if ((mod == 0) && (appear || pos == 2))
			return 1;
		else
			return 0;
	}
	int maxd = same ? s[pos]-'0' : 9;
	LL ans = 0;
	for (int i = 0; i <= maxd; i++) {
		if (((pos&1)&&(i == d)) || !(pos&1)&&(i != d) )
			continue;
		ans = (ans + dfs(pos+1, cal_mod(pos, mod, i), appear || (i == d), same && (i == maxd), s)) % MOD;
	}
	if (!same)
		dp[pos][mod][appear] = ans;
	return ans;
}

int judge(char *s)
{
	if (len == 1)
		if (s[1] != d && (s[1]-'0')%m == 0)
			return 1;
		else return 0;
	int cnt = 0, mod = 0;
	for (int i = 1; i <= len; i++)
	{
		mod = cal_mod(i, mod, s[i]-'0');
		if (((i&1) && (s[i]-'0' == d)) || (!(i&1) && (s[i]-'0' != d)))
			return 0;
	}
	return mod==0;
}

int main()
{
    //freopen("input.txt", "r", stdin);
	cin >> m >> d >> a+1 >> b+1;
	len = strlen(a+1);
	memset(dp, -1, sizeof(dp));
	LL ans = dfs(1, 0, 0, 1, b);
	memset(dp, -1, sizeof(dp));
	ans = ((ans - dfs(1, 0, 0, 1, a)) % MOD + MOD) % MOD;
	cout << ans+judge(a);
    return 0;
}


#include<bits/stdc++.h>
#define eps 1e-6
#define LL long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;

const int MOD = 1e9+7;
int m, d, len;
char a[3000], b[3000];
LL dp[2500][2500];

int pow_mod(int a, int n)
{
	if (n == 0)
		return 1 % m;
	int ans = pow_mod(a, n/2);
	ans = (LL)ans * ans % m;
	if (n&1)
		ans = (LL)ans * a % m;
	return ans;
}

int cal_mod(int pos, int mod, int digit)
{
	return ((LL)digit*pow_mod(10, len-pos) + mod) % m;
}

LL dfs(int pos, int mod, bool same, char* s)
{
	if (!same && (dp[pos][mod] != -1))
		return dp[pos][mod];
	if (pos > len) {
		if (mod == 0)
			return 1;
		else
			return 0;
	}
	int maxd = same ? s[pos]-'0' : 9;
	LL ans = 0;
	for (int i = 0; i <= maxd; i++) {
		if (((pos&1)&&(i == d)) || !(pos&1)&&(i != d) )
			continue;
		ans = (ans + dfs(pos+1, cal_mod(pos, mod, i), same && (i == maxd), s)) % MOD;
	}
	if (!same)
		dp[pos][mod] = ans;
	return ans;
}

int judge(char *s)
{
	int cnt = 0, mod = 0;
	for (int i = 1; i <= len; i++)
	{
		mod = cal_mod(i, mod, s[i]-'0');
		if (((i&1) && (s[i]-'0' == d)) || (!(i&1) && (s[i]-'0' != d)))
			return 0;
	}
	return mod==0;
}

int main()
{
    //freopen("input.txt", "r", stdin);
	cin >> m >> d >> a+1 >> b+1;
	len = strlen(a+1);
	memset(dp, -1, sizeof(dp));
	LL ans = dfs(1, 0, 1, b);
	memset(dp, -1, sizeof(dp));
	ans = ((ans - dfs(1, 0, 1, a)) % MOD + MOD) % MOD;
	cout << ans+judge(a);
    return 0;
}


#include<bits/stdc++.h>
#define eps 1e-6
#define LL long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;

const int MOD = 1e9+7;
int m, d, len;
char a[3000], b[3000];
LL dp[2500][2500];

LL dfs(int pos, int mod, bool same, char* s)
{
	if (!same && (dp[pos][mod] != -1))
		return dp[pos][mod];
	if (pos > len)
		return mod==0;
	int maxd = same ? s[pos]-'0' : 9;
	LL ans = 0;
	for (int i = 0; i <= maxd; i++) {
		if (((pos&1)&&(i == d)) || !(pos&1)&&(i != d) )
			continue;
		ans = (ans + dfs(pos+1, (mod*10+i)%m, same && (i == maxd), s)) % MOD;
	}
	if (!same)
		dp[pos][mod] = ans;
	return ans;
}

int judge(char *s)
{
	int cnt = 0, mod = 0;
	for (int i = 1; i <= len; i++)
	{
		mod = (mod*10 + s[i]-'0') % m;
		if (((i&1) && (s[i]-'0' == d)) || (!(i&1) && (s[i]-'0' != d)))
			return 0;
	}
	return mod==0;
}

int main()
{
    //freopen("input.txt", "r", stdin);
	cin >> m >> d >> a+1 >> b+1;
	len = strlen(a+1);
	memset(dp, -1, sizeof(dp));
	LL ans = dfs(1, 0, 1, b);
	memset(dp, -1, sizeof(dp));
	ans = ((ans - dfs(1, 0, 1, a)) % MOD + MOD) % MOD;
	cout << ans+judge(a);
    return 0;
}


#include <iostream>
#include <memory.h>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
#define ll long long
ll cc[4], temp[4];
const int mod = 1e9 + 7;
string s, t;
ll dp[2005][2000][2][2][2];
int m, d, n;
ll sol(int ind, int cur, int big, int least,int magic){
	if (ind == n){
		if ( magic && cur == 0)return 1;
		return 0;
	}
	ll &ret = dp[ind][cur][big][least][magic];
	if (ret != -1)return ret;
	ret = 0;
	int y, x, i, f = 0, lim = 9, next, l, b;
	if (big)lim = t[ind] - '0';
	if (least)f = s[ind] - '0';
	for (i = f; i <= lim; ++i){
		if (ind & 1){
			if ( i != d)continue;
		}
		else{
			if (i == d)continue;
		}
		next = (cur * 10 + i) % m;
		l = ((i == f) &least);
		b = ( (i == lim) & big);
		ret = (ret + sol(ind + 1, next, b, l,1) ) % mod;
	}
	return ret;
}
int main(){
	memset(dp, -1, sizeof(dp));
	ll ret = 0;
	int i, magic = 0, u;
	cin >> m >> d >> s >> t;
	if (d == 0)magic = 1;
	n = s.size();
	for (i = s[0] - '0'; i <= t[0] - '0'; ++i){
		if (i == d)continue;
		ret = (ret + sol(1, i%m, i == (t[0] - '0'), i == (s[0] - '0'),1 )) % mod;
	}
	cout << ret << endl;
}


#include <iostream>
#include <memory.h>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
#define ll long long
ll cc[4], temp[4];
const int mod = 1e9 + 7;
string s, t;
ll dp[2005][2000][2][2][2];
int m, d, n;
ll sol(int ind, int cur, int big, int least,int magic){
	if (ind == n){
		if ( magic && cur == 0)return 1;
		return 0;
	}
	ll &ret = dp[ind][cur][big][least][magic];
	if (ret != -1)return ret;
	ret = 0;
	int y, x, i, f = 0, lim = 9, next, l, b;
	if (big)lim = t[ind] - '0';
	if (least)f = s[ind] - '0';
	for (i = f; i <= lim; ++i){
		if (ind & 1){
			if ( i != d)continue;
		}
		else{
			if (i == d)continue;
		}
		next = (cur * 10 + i) % m;
		l = ((i == f) &least);
		b = ( (i == lim) & big);
		ret = (ret + sol(ind + 1, next, b, l,1) ) % mod;
	}
	return ret;
}
int main(){
	memset(dp, -1, sizeof(dp));
	ll ret = 0;
	int i, magic = 0, u;
	cin >> m >> d >> s >> t;
	if (d == 0)magic = 1;
	n = s.size();
	for (i = s[0] - '0'; i <= t[0] - '0'; ++i){
		if (i == d)continue;
		ret = (ret + sol(1, i%m, i == (t[0] - '0'), i == (s[0] - '0'),magic )) % mod;
	}
	cout << ret << endl;
}


#include <iostream>
#include <memory.h>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
#define ll long long
ll cc[4], temp[4];
const int mod = 1e9 + 7;
string s, t;
ll dp[2005][2000][2][2][2];
int m, d, n;
ll sol(int ind, int cur, int big, int least,int magic){
	if (ind == n){
		if ( magic && cur == 0)return 1;
		return 0;
	}
	ll &ret = dp[ind][cur][big][least][magic];
	if (ret != -1)return ret;
	ret = 0;
	int y, x, i, f = 0, lim = 9, next, l, b;
	if (big)lim = t[ind] - '0';
	if (least)f = s[ind] - '0';
	for (i = f; i <= lim; ++i){
		if (ind & 1){
			if (d != 0 && i != d)continue;
		}
		else{
			if (i == d)continue;
		}
		next = (cur * 10 + i) % m;
		l = ((i == f) &least);
		b = ( (i == lim) & big);
		ret = (ret + sol(ind + 1, next, b, l,1) ) % mod;
	}
	return ret;
}
int main(){
	memset(dp, -1, sizeof(dp));
	ll ret = 0;
	int i, magic = 0, u;
	cin >> m >> d >> s >> t;
	if (d == 0)magic = 1;
	n = s.size();
	for (i = s[0] - '0'; i <= t[0] - '0'; ++i){
		if (i == d)continue;
		ret = (ret + sol(1, i%m, i == (t[0] - '0'), i == (s[0] - '0'),magic )) % mod;
	}
	cout << ret << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int m, d;
string a, b, v;
int len;
const ll MOD = 1000000007;
int bypass = 0;
ll pd[2010][2010][2];
ll pwr[2010];

ll solve(int pos, int mod, int flag)
{
	if (pos >= len)
		return mod == 0 and (flag == 0 or bypass);

	if (pd[pos][mod][flag] != -1)
		return pd[pos][mod][flag];

	ll& ret = pd[pos][mod][flag];
	ret = 0;
	if (pos%2 == 1)
	{
		if (flag == 0)
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 0);
		else if (d < v[pos] - '0')
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 0);
		else if (d == v[pos] - '0')
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 1);
	}
	else
	{
		for (int i = 0; i < v[pos] - '0'; i++)
		{
			if (i == d) continue;
			if (i == 0 and pos == 0) continue;
			ret += solve(pos+1, (mod + i*pwr[pos])%m, 0);
		}
		ret += solve(pos+1, (mod + (v[pos]-'0')*pwr[pos])%m, 1);
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> m >> d >> a >> b;
	len = a.size();
	memset(pd, -1, sizeof(pd));
	ll ten = 1;
	for (int i = len-1; i >= 0; i--)
	{
		pwr[i] = ten;
		ten*=10;
		ten%=m;
	}
	v = a;
	ll la = solve(0, 0, 1);
	memset(pd, -1, sizeof(pd));
	v = b;
	bypass = 1;
	ll lb = solve(0, 0, 1);
	cout << lb-la << '\n';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int m, d;
string a, b, v;
int len;
const ll MOD = 1000000007;
int bypass = 0;
ll pd[2010][2010][2];
ll pwr[2010];

ll solve(int pos, int mod, int flag)
{
	if (pos >= len)
		return mod == 0 and (flag == 0 or bypass);

	if (pd[pos][mod][flag] != -1)
		return pd[pos][mod][flag];

	ll& ret = pd[pos][mod][flag];
	ret = 0;
	if (pos%2 == 1)
	{
		if (flag == 0)
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 0);
		else if (d < v[pos] - '0')
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 0);
		else if (d == v[pos] - '0')
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 1);
	}
	else
	{
		for (int i = 0; i < v[pos] - '0'; i++)
		{
			if (i == d) continue;
			ret += solve(pos+1, (mod + i*pwr[pos])%m, 0);
		}
		ret += solve(pos+1, (mod + (v[pos]-'0')*pwr[pos])%m, 1);
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> m >> d >> a >> b;
	len = a.size();
	memset(pd, -1, sizeof(pd));
	ll ten = 1;
	for (int i = len-1; i >= 0; i--)
	{
		pwr[i] = ten;
		ten*=10;
		ten%=m;
	}
	v = a;
	ll la = solve(0, 0, 1);
	memset(pd, -1, sizeof(pd));
	v = b;
	bypass = 1;
	ll lb = solve(0, 0, 1);
	cout << lb-la << '\n';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int m, d;
string a, b, v;
int len;
const ll MOD = 1000000007;
int bypass = 0;
ll pd[2010][2010][2];
ll pwr[2010];

ll solve(int pos, int mod, int flag)
{
	if (pos >= len)
		return mod == 0 and (flag == 0 or bypass);

	if (pd[pos][mod][flag] != -1)
		return pd[pos][mod][flag];

	ll& ret = pd[pos][mod][flag];
	ret = 0;
	if (pos%2 == 1)
	{
		if (flag == 0)
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 0);
		else if (d < v[pos] - '0')
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 0);
		else if (d == v[pos] - '0')
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 1);
	}
	else
	{
		if (flag == 0)
		{
			for (int i = 0; i <= 9; i++)
			{
				if (i == d) continue;
				if (i == 0 and pos == 0) continue;
				ret += solve(pos+1, (mod + i*pwr[pos])%m, 0);
			}
		}
		else
		{
			for (int i = 0; i <= v[pos] - '0'; i++)
			{
				if (i == d) continue;
				if (i == 0 and pos == 0) continue;
				if (i < v[pos] - '0')
					ret += solve(pos+1, (mod + i*pwr[pos])%m, 0);
				else
					ret += solve(pos+1, (mod + i*pwr[pos])%m, 1);
			}
		}
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> m >> d >> a >> b;
	len = a.size();
	memset(pd, -1, sizeof(pd));
	ll ten = 1;
	for (int i = len-1; i >= 0; i--)
	{
		pwr[i] = ten;
		ten*=10;
		ten%=m;
	}
	v = a;
	ll la = solve(0, 0, 1);
	memset(pd, -1, sizeof(pd));
	v = b;
	bypass = 1;
	ll lb = solve(0, 0, 1);
	//cout << la << " " << lb << '\n';
	cout << lb-la << '\n';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int m, d;
string a, b, v;
int len;
const ll MOD = 1000000007;
int bypass = 0;
ll pd[2010][2010][2];
ll pwr[2010];

ll solve(int pos, int mod, int flag)
{
	if (pos >= len)
		return mod == 0 and (flag == 0 or bypass);

	if (pd[pos][mod][flag] != -1)
		return pd[pos][mod][flag];

	ll& ret = pd[pos][mod][flag];
	ret = 0;
	if (pos%2 == 1)
	{
		if (flag == 0)
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 0);
		else if (d < v[pos] - '0')
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 0);
		else if (d == v[pos] - '0')
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 1);
	}
	else
	{
		if (flag == 0)
		{
			for (int i = 0; i <= 9; i++)
			{
				if (i == d) continue;
				if (i == 0 and pos == 0) continue;
				ret += solve(pos+1, (mod + i*pwr[pos])%m, 0);
				ret %= MOD;
			}
		}
		else
		{
			for (int i = 0; i <= v[pos] - '0'; i++)
			{
				if (i == d) continue;
				if (i == 0 and pos == 0) continue;
				if (i < v[pos] - '0')
					ret += solve(pos+1, (mod + i*pwr[pos])%m, 0);
				else
					ret += solve(pos+1, (mod + i*pwr[pos])%m, 1);
				ret %= MOD;
			}
		}
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> m >> d >> a >> b;
	len = a.size();
	memset(pd, -1, sizeof(pd));
	ll ten = 1;
	for (int i = len-1; i >= 0; i--)
	{
		pwr[i] = ten;
		ten*=10;
		ten%=m;
	}
	v = a;
	ll la = solve(0, 0, 1);
	memset(pd, -1, sizeof(pd));
	v = b;
	bypass = 1;
	ll lb = solve(0, 0, 1);
	//cout << la << " " << lb << '\n';
	cout << (MOD + lb-la)%MOD << '\n';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007LL;
char a[2010], b[2010];
int n, m, d;
ll pd[2010][2000][4];
ll pwr[2010];

ll solve(int pos, int mod, int flag)
{
	//printf("solve(%d, %d, %d)\n", pos, mod, flag);
	if (pos >= n)
	{
		//printf("solve(%d, %d, %d)\n", pos, mod, flag);
		return (mod == 0);
	}

	if (pd[pos][mod][flag] != -1)
		return pd[pos][mod][flag];

	ll& ret = pd[pos][mod][flag];
	ret = 0;
	int ad = a[pos] - '0', bd = b[pos] - '0';

	if (pos%2)
	{
		if (flag == 0)
		{
			if (d < ad or d > bd)
				ret = 0;
			else if (d > ad and d < bd)
				ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 3)%MOD;
			else if (d == ad)
				ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 2)%MOD;
			else
				ret = solve(pos+1, (mod*(d*pwr[pos])%m)%m, 1)%MOD;
		}
		else if (flag == 1)
		{
			if (d == bd)
				ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 1)%MOD;
			else if (d < bd)
				ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 3)%MOD;
			else
				ret = 0;
		}
		else if (flag == 2)
		{
			if (d == ad)
				ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 2)%MOD;
			else if (d > ad)
				ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 3)%MOD;
			else
				ret = 0;
		}
		else
			ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 3)%MOD;

		return ret;
	}

	if (flag == 0)	//sem garantias
	{
		if (ad == bd)
		{
			if (pos%2 == 0 and ad == d)
				ret = 0;
			else
				ret = solve(pos+1, (mod + (ad*pwr[pos])%m)%m, 0);
		}
		else
		{
			for (int i = ad; i <= bd; i++)
			{
				if (i == d and pos%2 == 0) continue;
				if (i == ad)
				{
					ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 2);
				}
				else if (i == bd)
				{
					ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 1);
				}
				else
				{
					ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 3);
				}
				ret %= MOD;
			}
		}
	}
	else if (flag == 1)	//garantido maior que a
	{
		for (int i = 0; i <= bd; i++)
		{
			if (i == d and pos%2 == 0) continue;
			if (i == bd)
				ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 1);
			else
				ret += solve(pos+1, (mod + (i*pwr[pos]%m))%m, 3);
			ret %= MOD;
		}
	}
	else if (flag == 2) //garantido menor que b
	{
		for (int i = ad; i <= 9; i++)
		{
			if (i == d and pos%2 == 0) continue;
			if (i == ad)
				ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 2);
			else
				ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 3);
			ret %= MOD;
		}
	}
	else //garantido maior que a e menor que b
	{
		for (int i = 0; i <= 9; i++)
		{
			if (i == d and pos%2 == 0) continue;
			ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 3);
			ret %= MOD;
		}
	}
	return ret;
}

int main()
{
	scanf("%d %d %s %s", &m, &d, a, b);
	n = strlen(a);
	memset(pd, -1, sizeof(pd));
	ll ten = 1;
	for (int i = n-1; i >= 0; i--)
	{
		pwr[i] = ten;
		ten*=10LL;
		ten %= m;
	}
	printf("%lld\n", solve(0, 0, 0));
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007LL;
char a[2010], b[2010];
int n, m, d;
ll pd[2010][2000][4];
ll pwr[2010];

ll solve(int pos, int mod, int flag)
{
	//printf("solve(%d, %d, %d)\n", pos, mod, flag);
	if (pos >= n)
	{
		//printf("solve(%d, %d, %d)\n", pos, mod, flag);
		return (mod == 0);
	}

	if (pd[pos][mod][flag] != -1)
		return pd[pos][mod][flag];

	ll& ret = pd[pos][mod][flag];
	ret = 0;
	int ad = a[pos] - '0', bd = b[pos] - '0';

	if (pos%2)
	{
		if (flag == 0)
		{
			if (d < ad or d > bd)
				ret = 0;
			else if (d > ad and d < bd)
				ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 3);
			else if (d == ad)
				ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 2);
			else
				ret = solve(pos+1, (mod*(d*pwr[pos])%m)%m, 1);
		}
		else if (flag == 1)
		{
			if (d == bd)
				ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 1);
			else if (d < bd)
				ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 3);
			else
				ret = 0;
		}
		else if (flag == 2)
		{
			if (d == ad)
				ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 2);
			else if (d > ad)
				ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 3);
			else
				ret = 0;
		}
		else
			ret = solve(pos+1, (mod + (d*pwr[pos])%m)%m, 3);

		return ret;
	}

	if (flag == 0)	//sem garantias
	{
		if (ad == bd)
		{
			if (pos%2 == 0 and ad == d)
				ret = 0;
			else
				ret = solve(pos+1, (mod + (ad*pwr[pos])%m)%m, 0);
		}
		else
		{
			for (int i = ad; i <= bd; i++)
			{
				if (i == d and pos%2 == 0) continue;
				if (i == ad)
				{
					ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 2);
				}
				else if (i == bd)
				{
					ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 1);
				}
				else
				{
					ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 3);
				}
				ret %= MOD;
			}
		}
	}
	else if (flag == 1)	//garantido maior que a
	{
		for (int i = 0; i <= bd; i++)
		{
			if (i == d and pos%2 == 0) continue;
			if (i == bd)
				ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 1);
			else
				ret += solve(pos+1, (mod + (i*pwr[pos]%m))%m, 3);
			ret %= MOD;
		}
	}
	else if (flag == 2) //garantido menor que b
	{
		for (int i = ad; i <= 9; i++)
		{
			if (i == d and pos%2 == 0) continue;
			if (i == ad)
				ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 2);
			else
				ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 3);
			ret %= MOD;
		}
	}
	else //garantido maior que a e menor que b
	{
		for (int i = 0; i <= 9; i++)
		{
			if (i == d and pos%2 == 0) continue;
			ret += solve(pos+1, (mod + (i*pwr[pos])%m)%m, 3);
			ret %= MOD;
		}
	}
	return ret;
}

int main()
{
	scanf("%d %d %s %s", &m, &d, a, b);
	n = strlen(a);
	memset(pd, -1, sizeof(pd));
	ll ten = 1;
	for (int i = n-1; i >= 0; i--)
	{
		pwr[i] = ten;
		ten*=10LL;
		ten %= m;
	}
	printf("%lld\n", solve(0, 0, 0));
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int m, d;
string a, b, v;
int len;
const ll MOD = 1000000007;
int bypass = 0;
ll pd[2010][2010][2];
ll pwr[2010];

ll solve(int pos, int mod, int flag)
{
	if (pos >= len)
		return mod == 0 and (flag == 0 or bypass);

	if (pd[pos][mod][flag] != -1)
		return pd[pos][mod][flag];

	ll& ret = pd[pos][mod][flag];
	ret = 0;
	if (pos%2 == 1)
	{
		if (flag == 0)
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 0);
		else if (d < v[pos] - '0')
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 0);
		else if (d == v[pos] - '0')
			ret = solve(pos+1, (mod + d*pwr[pos])%m, 1);
	}
	else
	{
		if (flag == 0)
		{
			for (int i = 0; i <= 9; i++)
			{
				if (i == d) continue;
				if (i == 0 and pos == 0) continue;
				ret += solve(pos+1, (mod + i*pwr[pos])%m, 0);
				ret %= MOD;
			}
		}
		else
		{
			for (int i = 0; i <= v[pos] - '0'; i++)
			{
				if (i == d) continue;
				if (i == 0 and pos == 0) continue;
				if (i < v[pos] - '0')
					ret += solve(pos+1, (mod + i*pwr[pos])%m, 0);
				else
					ret += solve(pos+1, (mod + i*pwr[pos])%m, 1);
				ret %= MOD;
			}
		}
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> m >> d >> a >> b;
	len = a.size();
	memset(pd, -1, sizeof(pd));
	ll ten = 1;
	for (int i = len-1; i >= 0; i--)
	{
		pwr[i] = ten;
		ten*=10;
		ten%=m;
	}
	v = a;
	ll la = solve(0, 0, 1);
	memset(pd, -1, sizeof(pd));
	v = b;
	bypass = 1;
	ll lb = solve(0, 0, 1);
	//cout << la << " " << lb << '\n';
	cout << lb-la << '\n';
	return 0;
}


#include <bits/stdc++.h>
#define inp freopen("data.inp","r",stdin)
#define out freopen("data.out","w",stdout)
#define ll long long
#define ull unsigned long long
#define db double
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define st first
#define nd second
#define inc(i,a,b) for (int i=(int)a; i<=(int)b; i++)
#define dec(i,a,b) for (int i=(int)a; i>=(int)b; i--)
#define inf (int)(2e9)
#define mod (int)(1e9+7)
#define pts(a) setprecision(a) << fixed
#define ln "\n"
#define readln scanf("\n")
#define free(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;

int n,m,d,lo,hi,ans;
string a,b,res;

void f(int pos,int x,int y) {
	if (pos>=n) {
		int md=0,ok=0,cnt=0;
		for (int i=1; i<n; i+=2) cnt++;
		for (int i=0; i<n; i++) {
			if (res[i]==char(d+48)) {
				if (i%2==1) ok++; else { ok=-1; break; }
			}
		}
		if (ok==cnt) {
			inc(i,0,n-1) md=(md*10+res[i]-'0')%m;
			if ((md==0)&&(a<=res)&&(res<=b)) ans=(ans+1)%mod;
		}
	} else {
		if (x==1) lo=a[pos]-'0'; else lo=0;
		if (y==1) hi=b[pos]-'0'; else hi=9;
		if (pos%2==1) {
			int xx=0,yy=0;
			if ((x==1)&&(d==lo)) xx=1;
			if ((y==1)&&(d==hi)) yy=1;
			if ((lo<=d)&&(d<=hi)) {
				res[pos]=char(d+48);
				f(pos+1,xx,yy);
			} else return;
		} else {
			inc(i,lo,hi) {
				int xx=0,yy=0;
				if ((x==1)&&(i==lo)) xx=1;
				if ((y==1)&&(i==hi)) yy=1;
				if (pos%2==0) {
					res[pos]=char(i+48);
					f(pos+1,xx,yy);
				}
			}
		}
	}
}

int main() {
	cin >> m >> d >> a >> b;
	n=max(a.size(),b.size());
	res="";
	while (res.size()<n) res=res+"0";
	f(0,1,1);
	cout << ans << ln;
}


#include <bits/stdc++.h>
#define inp freopen("data.inp","r",stdin)
#define out freopen("data.out","w",stdout)
#define ll long long
#define ull unsigned long long
#define db double
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define st first
#define nd second
#define inc(i,a,b) for (int i=(int)a; i<=(int)b; i++)
#define dec(i,a,b) for (int i=(int)a; i>=(int)b; i--)
#define inf (int)(2e9)
#define mod (int)(1e9+7)
#define pts(a) setprecision(a) << fixed
#define ln "\n"
#define readln scanf("\n")
#define free(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;

int n,m,d,lo,hi,ans;
string a,b,res;

void f(int pos,int x,int y) {
	if (pos>=n) {
		int md=0;
		inc(i,0,n-1) {
			md=(md*10+res[i]-'0')%m;
		}
		if (md==0) ans=(ans+1)%mod;
	} else {
		if (x==1) lo=a[pos]-'0'; else lo=0;
		if (y==1) hi=b[pos]-'0'; else hi=9;

		inc(i,lo,hi) {
			int xx,yy;
			if ((x==1)&&(i==a[pos]-'0')) xx=1; else xx=0;
			if ((y==1)&&(i==b[pos]-'0')) yy=1; else yy=0;
			if (i!=d) {
				res[pos]=char(i+48);
				f(pos+2,xx,yy);
				res[pos]='0';
			}
		}
	}
}

int main() {
	cin >> m >> d >> a >> b;
	n=max(a.size(),b.size());
	res="";
	while (res.size()<n) res=res+"0";
	for (int i=1; i<n; i+=2) res[i]=char(d+48);
	f(0,1,1);
	cout << ans << ln;
}


#include <bits/stdc++.h>
#define inp freopen("data.inp","r",stdin)
#define out freopen("data.out","w",stdout)
#define ll long long
#define ull unsigned long long
#define db double
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define st first
#define nd second
#define inc(i,a,b) for (ll i=(ll)a; i<=(ll)b; i++)
#define dec(i,a,b) for (ll i=(ll)a; i>=(ll)b; i--)
#define inf (ll)(2e9)
#define mod (ll)(1e9+7)
#define pts(a) setprecision(a) << fixed
#define ln "\n"
#define readln scanf("\n")
#define free(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;

ll n,m,d,ff[2002][2][2][2002];
string a,b,res;

ll f(ll pos,ll x,ll y,ll md) {
	if (pos==n) {
		if (md==0) return 1; else return 0;
	} else {
		if (ff[pos][x][y][md]!=-1) return ff[pos][x][y][md];
		ll lo,hi;
		if (x==1) lo=a[pos]-'0'; else lo=0;
		if (y==1) hi=b[pos]-'0'; else hi=9;
		ll ans=0;
		if (pos%2==1) {
			ll xx=0,yy=0;
			if ((x==1)&&(d==lo)) xx=1;
			if ((y==1)&&(d==hi)) yy=1;

			if ((lo<=d)&&(d<=hi)) {
				res[pos]=char(d+48);
				ans=(ans+f(pos+1,xx,yy,(md*10+d)%m)%mod)%mod;
			}
		} else {
			inc(i,lo,hi)
				if (i!=d) {
					ll xx=0,yy=0;
					if ((x==1)&&(i==lo)) xx=1;
					if ((y==1)&&(i==hi)) yy=1;
					res[pos]=char(i+48);
					ans=(ans+f(pos+1,xx,yy,(md*10+i)%m)%mod)%mod;
				}
		}
		return (ff[pos][x][y][md]=ans);
	}
}

int main() {
	while (cin >> m >> d >> a >> b) {
		inc(i,0,2000) inc(j,0,1) inc(k,0,1) inc(l,0,2000) ff[i][j][k][l]=-1;
		n=max(a.size(),b.size());
		res="";
		while (res.size()<n) res=res+"0";
		ll aa=f(0,1,1,0);
		cout << aa << ln;
	}
}