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


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


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


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[100][2][2002][100];
vector <int> num;
int d, m;

ll call(int idx, int tight, int x, int xi) {
    if(idx >= num.size()) {
        return (x > 0 && x % m == 0);
    }
    ll &ret = dp[idx][tight][x][xi];
    if(ret != -1) {
        return ret;
    }
    int LIM = (tight ? num[idx] : 9);
    ll sum = 0;
    if(xi % 2 == 0) {
        for(int i = 0; i <= LIM; i++) {
            if(i == d && d != 0) {
                continue;
            }
            int nt = (i == num[idx] ? 1 : 0);
            int nx = (x * 10 + i);
            int nxi = ((x == 0 && i == 0) ? xi : (xi + 1));
            sum += call(idx + 1, tight && nt, nx, nxi);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    } else {
        int nt = (d == num[idx] ? 1 : 0);
        int nx = (x * 10 + d);
        sum += call(idx + 1, tight && nt, nx, xi + 1);
        if(sum > MOD) {
            sum %= MOD;
        }
    }
    return ret = sum;
}

void encode(int n) {
    num.clear();
    while(n) {
        num.pb(n % 10);
        n /= 10;
    }
    reverse(all(num));
}

ll getx(int n) {
    memset(dp, -1, sizeof dp);
    encode(n);
    return call(0, 1, 0, 0);
}

int main() {
#ifdef HOMEPC
    read();
#endif

    int a, b;
    scanf("%d %d %d %d", &m, &d, &a, &b);
    ll ba = getx(b);
    ll aa = getx(a - 1);
    printf("%lld\n", ba - aa);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[2002][2][2][2002];
vector <int> numl, numh;
int d, m;
string l, h;

ll call(int idx, int tightl, int tighth, int x) {
    if(idx >= numl.size()) {
        return (x == 0);
    }
    ll &ret = dp[idx][tighth][tightl][x];
    if(ret != -1) {
        return ret;
    }
    int LIML = (tightl ? numl[idx] : 0);
    int LIMH = (tighth ? numh[idx] : 9);
    ll sum = 0;
    if(idx % 2 == 0) {
        for(int i = LIML; i <= LIMH; i++) {
            if(i == d) {
                continue;
            }
            int ntl = (i == numl[idx] ? 1 : 0);
            int nth = (i == numh[idx] ? 1 : 0);
            int nx = (x * 10 + i) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    } else {
        if((!tightl || d >= numl[idx]) && (!tighth || d <= numh[idx])) {
            int ntl = (d == numl[idx] ? 1 : 0);
            int nth = (d == numh[idx] ? 1 : 0);
            int nx = (x * 10 + d) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    }
    return ret = sum;
}

ll getx() {
    memset(dp, -1, sizeof dp);
    numl.clear();
    for(int i = 0; i < l.size(); i++) {
        numl.pb(l[i] - '0');
    }
    numh.clear();
    for(int i = 0; i < h.size(); i++) {
        numh.pb(h[i] - '0');
    }
    return call(0, 1, 1, 0);
}

char str[2002];

int main() {
#ifdef HOMEPC
    read();
#endif

    scanf("%d %d", &m, &d);
    scanf("%s", str);
    l = str;
    scanf("%s", str);
    h = str;
    ll ret = getx();
    printf("%lld\n", ret);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[2002][2][2][2002];
vector <int> numl, numh;
int d, m;

ll call(int idx, int tightl, int tighth, int x, int xi) {
    if(idx >= numl.size()) {
        return (x == 0);
    }
    ll &ret = dp[idx][tighth][tightl][x];
    if(ret != -1) {
        return ret;
    }
    int LIML = (tightl ? numl[idx] : 0);
    int LIMH = (tighth ? numh[idx] : 9);
    ll sum = 0;
    if(xi % 2 == 0) {
        for(int i = LIML; i <= LIMH; i++) {
            if(i == d) {
                continue;
            }
            int ntl = (i == numl[idx] ? 1 : 0);
            int nth = (i == numh[idx] ? 1 : 0);
            int nx = (x * 10 + i) % m;
            int nxi = ((x == 0 && i == 0) ? xi : (xi + 1));
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, nxi);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    } else {
        if((!tightl || d >= numl[idx]) && (!tighth || d <= numh[idx])) {
            int ntl = (d == numl[idx] ? 1 : 0);
            int nth = (d == numh[idx] ? 1 : 0);
            int nx = (x * 10 + d) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, xi + 1);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    }
    return ret = sum;
}

ll getx(string l, string h) {
    memset(dp, -1, sizeof dp);
    numl.clear();
    for(int i = 0; i < l.size(); i++) {
        numl.pb(l[i] - '0');
    }
    numh.clear();
    for(int i = 0; i < h.size(); i++) {
        numh.pb(h[i] - '0');
    }
    return call(0, 1, 1, 0, 0);
}

int main() {
#ifdef HOMEPC
    read();
#endif

    scanf("%d %d", &m, &d);
    string l, h;
    cin >> l >> h;
    ll ret = getx(l, h);
    printf("%lld\n", ret);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[10][2][2002][10];
vector <int> num;
int d, m;

ll call(int idx, int tight, int x, int xi) {
    if(idx >= num.size()) {
        return (x > 0 && x % m == 0);
    }
    ll &ret = dp[idx][tight][x][xi];
    if(ret != -1) {
        return ret;
    }
    int LIM = (tight ? num[idx] : 9);
    ll sum = 0;
    if(xi % 2 == 0) {
        for(int i = 0; i <= LIM; i++) {
            if(i == d && d != 0) {
                continue;
            }
            int nt = (i == num[idx] ? 1 : 0);
            int nx = (x * 10 + i);
            int nxi = ((x == 0 && i == 0) ? xi : (xi + 1));
            sum += call(idx + 1, tight && nt, nx, nxi);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    } else {
        if(d <= num[idx]) {
            int nt = (d == num[idx] ? 1 : 0);
            int nx = (x * 10 + d);
            sum += call(idx + 1, tight && nt, nx, xi + 1);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    }
    return ret = sum;
}

void encode(int n) {
    num.clear();
    while(n) {
        num.pb(n % 10);
        n /= 10;
    }
    reverse(all(num));
}

ll getx(int n) {
    memset(dp, -1, sizeof dp);
    encode(n);
    return call(0, 1, 0, 0);
}

int main() {
#ifdef HOMEPC
    read();
#endif

    int a, b;
    scanf("%d %d %d %d", &m, &d, &a, &b);
    ll ba = getx(b);
    ll aa = getx(a - 1);
    printf("%lld\n", ba - aa);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[2002][2][2][2002];
vector <int> numl, numh;
int d, m;

ll call(int idx, int tightl, int tighth, int x, int xi) {
    if(idx >= numl.size()) {
        return (x == 0);
    }
    ll &ret = dp[idx][tighth][tightl][x];
    if(ret != -1) {
        return ret;
    }
    int LIML = (tightl ? numl[idx] : 0);
    int LIMH = (tighth ? numh[idx] : 9);
    ll sum = 0;
    if(xi % 2 == 0) {
        for(int i = LIML; i <= LIMH; i++) {
            if(i == d) {
                continue;
            }
            int ntl = (i == numl[idx] ? 1 : 0);
            int nth = (i == numh[idx] ? 1 : 0);
            int nx = (x * 10 + i) % m;
            int nxi = ((x == 0 && i == 0) ? xi : (xi + 1));
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, nxi);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    } else {
        if((!tightl || d >= numl[idx]) && (!tighth || d <= numh[idx])) {
            int ntl = (d == numl[idx] ? 1 : 0);
            int nth = (d == numh[idx] ? 1 : 0);
            int nx = (x * 10 + d) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, xi + 1);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    }
    if(sum < 0) {
        sum = (sum + MOD) % MOD;
    }
    return ret = sum;
}

ll getx(string l, string h) {
    memset(dp, -1, sizeof dp);
    numl.clear();
    for(int i = 0; i < l.size(); i++) {
        numl.pb(l[i] - '0');
    }
    numh.clear();
    for(int i = 0; i < h.size(); i++) {
        numh.pb(h[i] - '0');
    }
    return call(0, 1, 1, 0, 0);
}

int main() {
#ifdef HOMEPC
    read();
#endif

    scanf("%d %d", &m, &d);
    string l, h;
    cin >> l >> h;
    ll ret = ((getx(l, h) % MOD) + MOD) % MOD;
    printf("%lld\n", ret);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[10][2][2002][10];
vector <int> num;
int d, m;

ll call(int idx, int tight, int x, int xi) {
    if(idx >= num.size()) {
        return (x > 0 && x % m == 0);
    }
    ll &ret = dp[idx][tight][x][xi];
    if(ret != -1) {
        return ret;
    }
    int LIM = (tight ? num[idx] : 9);
    ll sum = 0;
    if(xi % 2 == 0) {
        for(int i = 0; i <= LIM; i++) {
            if(i == d && d != 0) {
                continue;
            }
            int nt = (i == num[idx] ? 1 : 0);
            int nx = (x * 10 + i);
            int nxi = ((x == 0 && i == 0) ? xi : (xi + 1));
            sum += call(idx + 1, tight && nt, nx, nxi);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    } else {
        int nt = (d == num[idx] ? 1 : 0);
        int nx = (x * 10 + d);
        sum += call(idx + 1, tight && nt, nx, xi + 1);
        if(sum > MOD) {
            sum %= MOD;
        }
    }
    return ret = sum;
}

void encode(int n) {
    num.clear();
    while(n) {
        num.pb(n % 10);
        n /= 10;
    }
    reverse(all(num));
}

ll getx(int n) {
    memset(dp, -1, sizeof dp);
    encode(n);
    return call(0, 1, 0, 0);
}

int main() {
#ifdef HOMEPC
    read();
#endif

    int a, b;
    scanf("%d %d %d %d", &m, &d, &a, &b);
    ll ba = getx(b);
    ll aa = getx(a - 1);
    printf("%lld\n", ba - aa);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[2002][2][2][2002];
vector <int> numl, numh;
int d, m;
string l, h;

ll call(int idx, int tightl, int tighth, int x) {
    if(idx >= numl.size()) {
        return (x == 0);
    }
    ll &ret = dp[idx][tighth][tightl][x];
    if(ret != -1) {
        return ret;
    }
    int LIML = (tightl ? numl[idx] : 0);
    int LIMH = (tighth ? numh[idx] : 9);
    ll sum = 0;
    if(idx % 2 == 0) {
        for(int i = LIML; i <= LIMH; i++) {
            if(i == d) {
                continue;
            }
            int ntl = (i == numl[idx] ? 1 : 0);
            int nth = (i == numh[idx] ? 1 : 0);
            int nx = (x * 10 + i) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    } else {
        if((!tightl || d >= numl[idx]) && (!tighth || d <= numh[idx])) {
            int ntl = (d == numl[idx] ? 1 : 0);
            int nth = (d == numh[idx] ? 1 : 0);
            int nx = (x * 10 + d) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    }
    return ret = sum;
}

ll getx(string l, string h) {
    memset(dp, -1, sizeof dp);
    numl.clear();
    for(int i = 0; i < l.size(); i++) {
        numl.pb(l[i] - '0');
    }
    numh.clear();
    for(int i = 0; i < h.size(); i++) {
        numh.pb(h[i] - '0');
    }
    return call(0, 1, 1, 0);
}

char str[2002];

int main() {
#ifdef HOMEPC
    read();
#endif

    scanf("%d %d", &m, &d);
    scanf("%s", str);
    l = str;
    scanf("%s", str);
    h = str;
    ll ret = getx(l, h);
    printf("%lld\n", ret);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[2002][2][2][2002];
vector <int> numl, numh;
int d, m;

ll call(int idx, int tightl, int tighth, int x, int xi) {
    if(idx >= numl.size()) {
        return (x == 0);
    }
    ll &ret = dp[idx][tighth][tightl][x];
    if(ret != -1) {
        return ret;
    }
    int LIML = (tightl ? numl[idx] : 0);
    int LIMH = (tighth ? numh[idx] : 9);
    ll sum = 0;
    if(xi % 2 == 0) {
        for(int i = LIML; i <= LIMH; i++) {
            if(i == d && d != 0) {
                continue;
            }
            int ntl = (i == numl[idx] ? 1 : 0);
            int nth = (i == numh[idx] ? 1 : 0);
            int nx = (x * 10 + i) % m;
            int nxi = ((x == 0 && i == 0) ? xi : (xi + 1));
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, nxi);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    } else {
        if((!tightl || d >= numl[idx]) && (!tighth || d <= numh[idx])) {
            int ntl = (d == numl[idx] ? 1 : 0);
            int nth = (d == numh[idx] ? 1 : 0);
            int nx = (x * 10 + d) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, xi + 1);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    }
    return ret = sum;
}

ll getx(string l, string h) {
    memset(dp, -1, sizeof dp);
    numl.clear();
    for(int i = 0; i < l.size(); i++) {
        numl.pb(l[i] - '0');
    }
    numh.clear();
    for(int i = 0; i < h.size(); i++) {
        numh.pb(h[i] - '0');
    }
    return call(0, 1, 1, 0, 0);
}

int main() {
#ifdef HOMEPC
    read();
#endif

    scanf("%d %d", &m, &d);
    string l, h;
    cin >> l >> h;
    ll ret = getx(l, h);
    printf("%lld\n", ret);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[2002][2][2][2002][2];
vector <int> numl, numh;
int d, m;

ll call(int idx, int tightl, int tighth, int x, int xi) {
    if(idx >= numl.size()) {
        return (x == 0);
    }
    ll &ret = dp[idx][tighth][tightl][x][x & 1];
    if(ret != -1) {
        return ret;
    }
    int LIML = (tightl ? numl[idx] : 0);
    int LIMH = (tighth ? numh[idx] : 9);
    ll sum = 0;
    if(xi % 2 == 0) {
        for(int i = LIML; i <= LIMH; i++) {
            if(i == d) {
                continue;
            }
            int ntl = (i == numl[idx] ? 1 : 0);
            int nth = (i == numh[idx] ? 1 : 0);
            int nx = (x * 10 + i) % m;
            int nxi = ((x == 0 && i == 0) ? xi : (xi + 1));
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, nxi);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    } else {
        if((!tightl || d >= numl[idx]) && (!tighth || d <= numh[idx])) {
            int ntl = (d == numl[idx] ? 1 : 0);
            int nth = (d == numh[idx] ? 1 : 0);
            int nx = (x * 10 + d) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, xi + 1);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    }
    if(sum < 0) {
        sum = (sum + MOD) % MOD;
    }
    return ret = sum;
}

ll getx(string l, string h) {
    memset(dp, -1, sizeof dp);
    numl.clear();
    for(int i = 0; i < l.size(); i++) {
        numl.pb(l[i] - '0');
    }
    numh.clear();
    for(int i = 0; i < h.size(); i++) {
        numh.pb(h[i] - '0');
    }
    return call(0, 1, 1, 0, 0);
}

int main() {
#ifdef HOMEPC
    read();
#endif

    scanf("%d %d", &m, &d);
    string l, h;
    cin >> l >> h;
    ll ret = ((getx(l, h) % MOD) + MOD) % MOD;
    printf("%lld\n", ret);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[2002][2][2][2002];
vector <int> numl, numh;
int d, m;

ll call(int idx, int tightl, int tighth, int x, int xi) {
    if(idx >= numl.size()) {
        return (x == 0);
    }
    ll &ret = dp[idx][tighth][tightl][x];
    if(ret != -1) {
        return ret;
    }
    int LIML = (tightl ? numl[idx] : 0);
    int LIMH = (tighth ? numh[idx] : 9);
    ll sum = 0;
    if(xi % 2 == 0) {
        for(int i = LIML; i <= LIMH; i++) {
            if(i == d && d == 0) {
                continue;
            }
            int ntl = (i == numl[idx] ? 1 : 0);
            int nth = (i == numh[idx] ? 1 : 0);
            int nx = (x * 10 + i) % m;
            int nxi = ((x == 0 && i == 0) ? xi : (xi + 1));
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, nxi);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    } else {
        if((!tightl || d >= numl[idx]) && (!tighth || d <= numh[idx])) {
            int ntl = (d == numl[idx] ? 1 : 0);
            int nth = (d == numh[idx] ? 1 : 0);
            int nx = (x * 10 + d) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, xi + 1);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    }
    return ret = sum;
}

ll getx(string l, string h) {
    memset(dp, -1, sizeof dp);
    numl.clear();
    for(int i = 0; i < l.size(); i++) {
        numl.pb(l[i] - '0');
    }
    numh.clear();
    for(int i = 0; i < h.size(); i++) {
        numh.pb(h[i] - '0');
    }
    return call(0, 1, 1, 0, 0);
}

int main() {
#ifdef HOMEPC
    read();
#endif

    scanf("%d %d", &m, &d);
    string l, h;
    cin >> l >> h;
    ll ret = getx(l, h);
    printf("%lld\n", ret);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[2002][2][2][2002];
vector <int> numl, numh;
int d, m;
char l[2002], h[2002];

ll call(int idx, int tightl, int tighth, int x) {
    if(idx >= numl.size()) {
        return (x == 0);
    }
    ll &ret = dp[idx][tighth][tightl][x];
    if(ret != -1) {
        return ret;
    }
    int LIML = (tightl ? numl[idx] : 0);
    int LIMH = (tighth ? numh[idx] : 9);
    ll sum = 0;
    if(idx % 2 == 0) {
        for(int i = LIML; i <= LIMH; i++) {
            if(i == d) {
                continue;
            }
            int ntl = (i == numl[idx] ? 1 : 0);
            int nth = (i == numh[idx] ? 1 : 0);
            int nx = (x * 10 + i) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    } else {
        if((!tightl || d >= numl[idx]) && (!tighth || d <= numh[idx])) {
            int ntl = (d == numl[idx] ? 1 : 0);
            int nth = (d == numh[idx] ? 1 : 0);
            int nx = (x * 10 + d) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    }
    return ret = sum;
}

ll getx() {
    memset(dp, -1, sizeof dp);
    numl.clear();
    int szl = strlen(l);
    for(int i = 0; i < szl; i++) {
        numl.pb(l[i] - '0');
    }
    numh.clear();
    int szh = strlen(h);
    for(int i = 0; i < szh; i++) {
        numh.pb(h[i] - '0');
    }
    return call(0, 1, 1, 0);
}

int main() {
#ifdef HOMEPC
    read();
#endif

    scanf("%d %d %s %s", &m, &d, l, h);
    ll ret = getx();
    printf("%lld\n", ret);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[10][2][2002][10];
vector <int> num;
int d, m;

ll call(int idx, int tight, int x, int xi) {
    if(idx >= num.size()) {
        return (x > 0 && x % m == 0);
    }
    ll &ret = dp[idx][tight][x][xi];
    if(ret != -1) {
        return ret;
    }
    int LIM = (tight ? num[idx] : 9);
    ll sum = 0;
    if(xi % 2 == 0) {
        for(int i = 0; i <= LIM; i++) {
            if(i == d && d != 0) {
                continue;
            }
            int nt = (i == num[idx] ? 1 : 0);
            int nx = (x * 10 + i);
            int nxi = ((x == 0 && i == 0) ? xi : (xi + 1));
            sum += call(idx + 1, tight && nt, nx, nxi);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    } else {
        if(!tight || d <= num[idx]) {
            int nt = (d == num[idx] ? 1 : 0);
            int nx = (x * 10 + d);
            sum += call(idx + 1, tight && nt, nx, xi + 1);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    }
    return ret = sum;
}

void encode(int n) {
    num.clear();
    while(n) {
        num.pb(n % 10);
        n /= 10;
    }
    reverse(all(num));
}

ll getx(int n) {
    memset(dp, -1, sizeof dp);
    encode(n);
    return call(0, 1, 0, 0);
}

int main() {
#ifdef HOMEPC
    read();
#endif

    int a, b;
    scanf("%d %d %d %d", &m, &d, &a, &b);
    ll ba = getx(b);
    ll aa = getx(a - 1);
    printf("%lld\n", ba - aa);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[2002][2][2][2002];
vector <int> numl, numh;
int d, m;

ll call(int idx, int tightl, int tighth, int x, int xi) {
    if(idx >= numl.size()) {
        return (x == 0);
    }
    ll &ret = dp[idx][tighth][tightl][x];
    if(ret != -1) {
        return ret;
    }
    int LIML = (tightl ? numl[idx] : 0);
    int LIMH = (tighth ? numh[idx] : 9);
    ll sum = 0;
    if(idx % 2 == 0) {
        for(int i = LIML; i <= LIMH; i++) {
            if(i == d) {
                continue;
            }
            int ntl = (i == numl[idx] ? 1 : 0);
            int nth = (i == numh[idx] ? 1 : 0);
            int nx = (x * 10 + i) % m;
            int nxi = ((x == 0 && i == 0) ? xi : (xi + 1));
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, nxi);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    } else {
        if((!tightl || d >= numl[idx]) && (!tighth || d <= numh[idx])) {
            int ntl = (d == numl[idx] ? 1 : 0);
            int nth = (d == numh[idx] ? 1 : 0);
            int nx = (x * 10 + d) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, xi + 1);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    }
    if(sum < 0) {
        sum = (sum + MOD) % MOD;
    }
    return ret = sum;
}

ll getx(string l, string h) {
    memset(dp, -1, sizeof dp);
    numl.clear();
    for(int i = 0; i < l.size(); i++) {
        numl.pb(l[i] - '0');
    }
    numh.clear();
    for(int i = 0; i < h.size(); i++) {
        numh.pb(h[i] - '0');
    }
    return call(0, 1, 1, 0, 0);
}

int main() {
#ifdef HOMEPC
    read();
#endif

    scanf("%d %d", &m, &d);
    string l, h;
    cin >> l >> h;
    ll ret = ((getx(l, h) % MOD) + MOD) % MOD;
    printf("%lld\n", ret);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[2002][2][2][2002];
vector <int> numl, numh;
int d, m;

ll call(int idx, int tightl, int tighth, int x, int xi) {
    if(idx >= numl.size()) {
        return (x == 0);
    }
    ll &ret = dp[idx][tighth][tightl][x];
    if(ret != -1) {
        return ret;
    }
    int LIML = (tightl ? numl[idx] : 0);
    int LIMH = (tighth ? numh[idx] : 9);
    ll sum = 0;
    if(xi % 2 == 0) {
        for(int i = LIML; i <= LIMH; i++) {
            if(i == d && d != 0) {
                continue;
            }
            int ntl = (i == numl[idx] ? 1 : 0);
            int nth = (i == numh[idx] ? 1 : 0);
            int nx = (x * 10 + i) % m;
            int nxi = ((x == 0 && i == 0) ? xi : (xi + 1));
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, nxi);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    } else {
        if((!tightl && !tighth) || (d >= numl[idx] && d <= numh[idx])) {
            int ntl = (d == numl[idx] ? 1 : 0);
            int nth = (d == numh[idx] ? 1 : 0);
            int nx = (x * 10 + d) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx, xi + 1);
            if(sum > MOD) {
                sum %= MOD;
            }
        }
    }
    return ret = sum;
}

ll getx(string l, string h) {
    memset(dp, -1, sizeof dp);
    numl.clear();
    for(int i = 0; i < l.size(); i++) {
        numl.pb(l[i] - '0');
    }
    numh.clear();
    for(int i = 0; i < h.size(); i++) {
        numh.pb(h[i] - '0');
    }
    return call(0, 1, 1, 0, 0);
}

int main() {
#ifdef HOMEPC
    read();
#endif

    scanf("%d %d", &m, &d);
    string l, h;
    cin >> l >> h;
    ll ret = getx(l, h);
    printf("%lld\n", ret);
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define cpp_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORIT(it, x) for (__typeof__((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(A) A.begin(), A.end()
#define mem(A) memset(A, 0, sizeof(A))
#define FF first
#define SS second
#define pb push_back
#define dbgA(A, n) { cerr << "-> " << #A << " = "; FOR(z, n) cerr << A[z] << " "; cerr << "\n"; }
#define dbgA2(A, n, m) { cerr << "-> " << #A << " = \n"; FOR(y, n) { FOR(z, m) cerr << A[y][z] << " "; cerr << "\n"; } }
#define dbg(args...) { cerr << "--> "; debugger::call(#args, args); cerr << "\n"; }
struct debugger {
    static void call(const char* it) {}
    template <typename T, typename... valT>
    static void call(const char* it, T val, valT... rest) {
        string var = "";
        for (; *it && *it != ','; it++)
            if (*it != ' ')
                var += *it;
        cerr << var << '=' << val << " ";
        call(++it, rest...);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};  /// 4 Direction
/// int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};  /// 8 Direction
/// int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1};  /// 8 Knight Direction
/// int dx[] = {2, -2, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1};  /// 6 Hexagonal Direction

const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

ll dp[2002][2][2][2002];
vector <int> numl, numh;
int d, m;

ll call(int idx, int tightl, int tighth, int x) {
    if(idx >= numl.size()) {
        return (x == 0);
    }
    ll &ret = dp[idx][tighth][tightl][x];
    if(ret != -1) {
        return ret;
    }
    int LIML = (tightl ? numl[idx] : 0);
    int LIMH = (tighth ? numh[idx] : 9);
    ll sum = 0;
    if(idx % 2 == 0) {
        for(int i = LIML; i <= LIMH; i++) {
            if(i == d) {
                continue;
            }
            int ntl = (i == numl[idx] ? 1 : 0);
            int nth = (i == numh[idx] ? 1 : 0);
            int nx = (x * 10 + i) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    } else {
        if((!tightl || d >= numl[idx]) && (!tighth || d <= numh[idx])) {
            int ntl = (d == numl[idx] ? 1 : 0);
            int nth = (d == numh[idx] ? 1 : 0);
            int nx = (x * 10 + d) % m;
            sum += call(idx + 1, tightl && ntl, tighth && nth, nx);
            if(sum >= MOD) {
                sum %= MOD;
            }
        }
    }
    return ret = sum;
}

ll getx(string l, string h) {
    memset(dp, -1, sizeof dp);
    numl.clear();
    for(int i = 0; i < l.size(); i++) {
        numl.pb(l[i] - '0');
    }
    numh.clear();
    for(int i = 0; i < h.size(); i++) {
        numh.pb(h[i] - '0');
    }
    return call(0, 1, 1, 0);
}

int main() {
#ifdef HOMEPC
    read();
#endif

    scanf("%d %d", &m, &d);
    string l, h;
    cin >> l >> h;
    ll ret = getx(l, h);
    printf("%lld\n", ret);
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define inf 0x3f3f3f3f
#define endl "\n"
#define ii pair<long long, long long>

using namespace std;

vector<int> number;
ll mult, d;
ll dp[4][4][2];
ll mod = 1e9+7;

ll solve(int pos, int qtt, bool smaller, string str){
    if(pos == number.size()){
        if((qtt > 0 || d == 0 ) && stoi(str)%mult == 0){
            //cout << str << endl;
            return true;
        }
        return false;
    }
    if(dp[pos][qtt][smaller] != -1) return dp[pos][qtt][smaller];

    ll ans = 0;
    int lim = (smaller) ? 9 : number[pos];

    for(int digit = 0 ; digit <= lim ; digit++){
        bool newSmaller = smaller;
        if(!smaller && digit < lim) newSmaller = true;
        if(pos%2 == 0 && digit == d) continue;
        ans += solve(pos+1, qtt + (digit==d), newSmaller, str + to_string(digit))%mod;
    }

    dp[pos][qtt][smaller] = ans;
    return ans;
}

bool isMagic(ll value){
    if(value%mult == 0){
        string str = to_string(value);
        for(int i = 0 ; i < str.size() ; i += 2){
            if(str[i] == d) return false;
        }
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll lb, ub;
    cin >> mult >> d >> lb >> ub;

    number.clear();
    memset(dp, -1, sizeof dp);
    string str = to_string(ub);
    for(int i = 0 ; i < str.size() ; i++) number.push_back(str[i]-'0');

    ll value1 = solve(0, 0, false, "");

    number.clear();
    memset(dp, -1, sizeof dp);
    str = to_string(lb);
    for(int i = 0 ; i < str.size() ; i++) number.push_back(str[i]-'0');

    ll value2;
    if(lb > 0) value2 = solve(0, 0, false, "");
    else value2 = 0;

    if(isMagic(lb)) value2 -= 1;

    cout << (value1 - value2)%mod << endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define inf 0x3f3f3f3f
#define endl "\n"
#define ii pair<long long, long long>

using namespace std;

vector<int> number;
ll mult, d;
ll dp[2005][2][2005];
ll mod = 1e9+7;

ll solve(int pos, int qtt, bool smaller, int num){
    if(pos == number.size()){
        if(num%mult == 0) return true;
        return false;
    }
    if(dp[pos][smaller][num] != -1) return dp[pos][smaller][num];

    ll ans = 0;
    int lim = (smaller) ? 9 : number[pos];

    for(int digit = 0 ; digit <= lim ; digit++){
        if((pos%2 == 0 && digit == d) || (pos%2 != 0 && digit != d)) continue;
        bool newSmaller = smaller;
        if(!smaller && digit < lim) newSmaller = true;
        ans += solve(pos+1, qtt + (digit==d), newSmaller, (10*num + digit)%mult)%mod;
    }

    dp[pos][smaller][num] = ans;
    return ans;
}

bool isMagic(string str){
    if(str.size() > 7) str = str.substr(str.size()-7, 7);
    if(stoi(str)%mult == 0){
        for(int i = 0 ; i < str.size() ; i++){
            if((i%2 != 0 && str[i]-'0' != d) || (i%2 == 0 && str[i]-'0' == d)) return false;
        }
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    string lb, ub;
    cin >> mult >> d >> lb >> ub;

    number.clear();
    memset(dp, -1, sizeof dp);
    for(int i = 0 ; i < ub.size() ; i++) number.push_back(ub[i]-'0');

    ll value1 = solve(0, 0, false, 0);

    number.clear();
    memset(dp, -1, sizeof dp);
    for(int i = 0 ; i < lb.size() ; i++) number.push_back(lb[i]-'0');

    ll value2;
    if(lb != "0") value2 = solve(0, 0, false, 0);
    else value2 = 0;

    if(isMagic(lb)) value1 += 1;

    cout << (value1 - value2)%mod << endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define inf 0x3f3f3f3f
#define endl "\n"
#define ii pair<long long, long long>

using namespace std;

vector<int> number;
ll mult, d;
ll dp[2005][2][2005];
ll mod = 1e9+7;

ll solve(int pos, int qtt, bool smaller, int num){
    if(pos == number.size()){
        if(num%mult == 0){
            //cout << str << endl;
            return true;
        }
        return false;
    }
    if(dp[pos][smaller][num] != -1) return dp[pos][smaller][num];

    ll ans = 0;
    int lim = (smaller) ? 9 : number[pos];

    for(int digit = 0 ; digit <= lim ; digit++){
        bool newSmaller = smaller;
        if(!smaller && digit < lim) newSmaller = true;
        if((pos%2 == 0 && digit == d) || (pos%2 != 0 && digit != d)) continue;
        ans += solve(pos+1, qtt + (digit==d), newSmaller, (10*num + digit)%mult)%mod;
    }

    dp[pos][smaller][num] = ans;
    return ans;
}

bool isMagic(ll value){
    if(value%mult == 0){
        string str = to_string(value);
        ll qtt = 0;
        for(int i = 0 ; i < str.size() ; i++){
            if(str[i] == d){
                if(i%2 != 0) qtt++;
                else return false;
            }
        }
        if(qtt) return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    string lb, ub;
    cin >> mult >> d >> lb >> ub;

    number.clear();
    memset(dp, -1, sizeof dp);
    for(int i = 0 ; i < ub.size() ; i++) number.push_back(ub[i]-'0');

    ll value1 = solve(0, 0, false, 0);

    number.clear();
    memset(dp, -1, sizeof dp);
    for(int i = 0 ; i < lb.size() ; i++) number.push_back(lb[i]-'0');

    ll value2;
    if(lb != "0") value2 = solve(0, 0, false, 0);
    else value2 = 0;

    cout << (value1 - value2)%mod << endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define inf 0x3f3f3f3f
#define endl "\n"
#define ii pair<long long, long long>

using namespace std;

vector<int> number;
ll mult, d;
ll dp[2005][4][2][2005];
ll mod = 1e9+7;

ll solve(int pos, int qtt, bool smaller, int num){
    if(pos == number.size()){
        if((qtt > 0 || d == 0 ) && num%mult == 0){
            //cout << str << endl;
            return true;
        }
        return false;
    }
    if(dp[pos][qtt][smaller][num] != -1) return dp[pos][qtt][smaller][num];

    ll ans = 0;
    int lim = (smaller) ? 9 : number[pos];

    for(int digit = 0 ; digit <= lim ; digit++){
        bool newSmaller = smaller;
        if(!smaller && digit < lim) newSmaller = true;
        if((pos%2 == 0 && digit == d) || (pos%2 != 0 && digit != d)) continue;
        ans += solve(pos+1, qtt + (digit==d), newSmaller, (10*num + digit)%mult)%mod;
    }

    dp[pos][qtt][smaller][num] = ans;
    return ans;
}

bool isMagic(ll value){
    if(value%mult == 0){
        string str = to_string(value);
        ll qtt = 0;
        for(int i = 0 ; i < str.size() ; i++){
            if(str[i] == d){
                if(i%2 != 0) qtt++;
                else return false;
            }
        }
        if(qtt) return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    string lb, ub;
    cin >> mult >> d >> lb >> ub;

    number.clear();
    memset(dp, -1, sizeof dp);
    for(int i = 0 ; i < ub.size() ; i++) number.push_back(ub[i]-'0');

    ll value1 = solve(0, 0, false, 0);

    number.clear();
    memset(dp, -1, sizeof dp);
    for(int i = 0 ; i < lb.size() ; i++) number.push_back(lb[i]-'0');

    ll value2;
    if(lb != "0") value2 = solve(0, 0, false, 0);
    else value2 = 0;

    cout << (value1 - value2)%mod << endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define inf 0x3f3f3f3f
#define endl "\n"
#define ii pair<long long, long long>

using namespace std;

vector<int> number;
ll mult, d;
ll dp[2005][4][2][2005];
ll mod = 1e9+7;

ll solve(int pos, int qtt, bool smaller, int num){
    if(pos == number.size()){
        if((qtt > 0 || d == 0 ) && num%mult == 0){
            //cout << str << endl;
            return true;
        }
        return false;
    }
    if(dp[pos][qtt][smaller][num] != -1) return dp[pos][qtt][smaller][num];

    ll ans = 0;
    int lim = (smaller) ? 9 : number[pos];

    for(int digit = 0 ; digit <= lim ; digit++){
        bool newSmaller = smaller;
        if(!smaller && digit < lim) newSmaller = true;
        if((pos%2 == 0 && digit == d) || (pos%2 != 0 && digit != d)) continue;
        ans += solve(pos+1, qtt + (digit==d), newSmaller, 10*num + digit)%mod;
    }

    dp[pos][qtt][smaller][num] = ans;
    return ans;
}

bool isMagic(ll value){
    if(value%mult == 0){
        string str = to_string(value);
        ll qtt = 0;
        for(int i = 0 ; i < str.size() ; i++){
            if(str[i] == d){
                if(i%2 != 0) qtt++;
                else return false;
            }
        }
        if(qtt) return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll lb, ub;
    cin >> mult >> d >> lb >> ub;

    number.clear();
    memset(dp, -1, sizeof dp);
    string str = to_string(ub);
    for(int i = 0 ; i < str.size() ; i++) number.push_back(str[i]-'0');

    ll value1 = solve(0, 0, false, 0);

    number.clear();
    memset(dp, -1, sizeof dp);
    str = to_string(lb);
    for(int i = 0 ; i < str.size() ; i++) number.push_back(str[i]-'0');

    ll value2;
    if(lb > 0) value2 = solve(0, 0, false, 0);
    else value2 = 0;

    if(isMagic(lb)) value2 -= 1;

    cout << (value1 - value2)%mod << endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define inf 0x3f3f3f3f
#define endl "\n"
#define ii pair<long long, long long>

using namespace std;

vector<int> number;
ll mult, d;
ll dp[2005][2][2005];
ll mod = 1e9+7;

ll solve(int pos, int qtt, bool smaller, int num){
    if(pos == number.size()){
        if(num%mult == 0) return true;
        return false;
    }
    if(dp[pos][smaller][num] != -1) return dp[pos][smaller][num];

    ll ans = 0;
    int lim = (smaller) ? 9 : number[pos];

    for(int digit = 0 ; digit <= lim ; digit++){
        if((pos%2 == 0 && digit == d) || (pos%2 != 0 && digit != d)) continue;
        bool newSmaller = smaller;
        if(!smaller && digit < lim) newSmaller = true;
        ans += solve(pos+1, qtt + (digit==d), newSmaller, (10*num + digit)%mult)%mod;
    }

    dp[pos][smaller][num] = ans;
    return ans;
}

bool isMagic(string str){
    if(str.size() > 10) str = str.substr(str.size()-10, 10);
    if(stoi(str)%mult == 0){
        for(int i = 0 ; i < str.size() ; i++){
            if((i%2 != 0 && str[i]-'0' != d) || (i%2 == 0 && str[i]-'0' == d)) return false;
        }
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    string lb, ub;
    cin >> mult >> d >> lb >> ub;

    number.clear();
    memset(dp, -1, sizeof dp);
    for(int i = 0 ; i < ub.size() ; i++) number.push_back(ub[i]-'0');

    ll value1 = solve(0, 0, false, 0);

    number.clear();
    memset(dp, -1, sizeof dp);
    for(int i = 0 ; i < lb.size() ; i++) number.push_back(lb[i]-'0');

    ll value2;
    if(lb != "0") value2 = solve(0, 0, false, 0);
    else value2 = 0;

    if(isMagic(lb)) value1 += 1;

    cout << (value1 - value2)%mod << endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define inf 0x3f3f3f3f
#define endl "\n"
#define ii pair<long long, long long>

using namespace std;

vector<int> number;
ll mult, d;
ll dp[4][4][2][2005];
ll mod = 1e9+7;

ll solve(int pos, int qtt, bool smaller, int num){
    if(pos == number.size()){
        if((qtt > 0 || d == 0 ) && num%mult == 0){
            //cout << str << endl;
            return true;
        }
        return false;
    }
    if(dp[pos][qtt][smaller][num] != -1) return dp[pos][qtt][smaller][num];

    ll ans = 0;
    int lim = (smaller) ? 9 : number[pos];

    for(int digit = 0 ; digit <= lim ; digit++){
        bool newSmaller = smaller;
        if(!smaller && digit < lim) newSmaller = true;
        if((pos%2 == 0 && digit == d) || (pos%2 != 0 && digit != d)) continue;
        ans += solve(pos+1, qtt + (digit==d), newSmaller, 10*num + digit)%mod;
    }

    dp[pos][qtt][smaller][num] = ans;
    return ans;
}

bool isMagic(ll value){
    if(value%mult == 0){
        string str = to_string(value);
        ll qtt = 0;
        for(int i = 0 ; i < str.size() ; i++){
            if(str[i] == d){
                if(i%2 != 0) qtt++;
                else return false;
            }
        }
        if(qtt) return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll lb, ub;
    cin >> mult >> d >> lb >> ub;

    number.clear();
    memset(dp, -1, sizeof dp);
    string str = to_string(ub);
    for(int i = 0 ; i < str.size() ; i++) number.push_back(str[i]-'0');

    ll value1 = solve(0, 0, false, 0);

    number.clear();
    memset(dp, -1, sizeof dp);
    str = to_string(lb);
    for(int i = 0 ; i < str.size() ; i++) number.push_back(str[i]-'0');

    ll value2;
    if(lb > 0) value2 = solve(0, 0, false, 0);
    else value2 = 0;

    if(isMagic(lb)) value2 -= 1;

    cout << (value1 - value2)%mod << endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define inf 0x3f3f3f3f
#define endl "\n"
#define ii pair<long long, long long>

using namespace std;

vector<int> number;
ll mult, d;
ll dp[2005][1000][2][2005];
ll mod = 1e9+7;

ll solve(int pos, int qtt, bool smaller, int num){
    if(pos == number.size()){
        if((qtt > 0 || d == 0 ) && num%mult == 0){
            //cout << str << endl;
            return true;
        }
        return false;
    }
    if(dp[pos][qtt][smaller][num] != -1) return dp[pos][qtt][smaller][num];

    ll ans = 0;
    int lim = (smaller) ? 9 : number[pos];

    for(int digit = 0 ; digit <= lim ; digit++){
        bool newSmaller = smaller;
        if(!smaller && digit < lim) newSmaller = true;
        if((pos%2 == 0 && digit == d) || (pos%2 != 0 && digit != d)) continue;
        ans += solve(pos+1, qtt + (digit==d), newSmaller, (10*num + digit)%mult)%mod;
    }

    dp[pos][qtt][smaller][num] = ans;
    return ans;
}

bool isMagic(ll value){
    if(value%mult == 0){
        string str = to_string(value);
        ll qtt = 0;
        for(int i = 0 ; i < str.size() ; i++){
            if(str[i] == d){
                if(i%2 != 0) qtt++;
                else return false;
            }
        }
        if(qtt) return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    string lb, ub;
    cin >> mult >> d >> lb >> ub;

    number.clear();
    memset(dp, -1, sizeof dp);
    for(int i = 0 ; i < ub.size() ; i++) number.push_back(ub[i]-'0');

    ll value1 = solve(0, 0, false, 0);

    number.clear();
    memset(dp, -1, sizeof dp);
    for(int i = 0 ; i < lb.size() ; i++) number.push_back(lb[i]-'0');

    ll value2;
    if(lb != "0") value2 = solve(0, 0, false, 0);
    else value2 = 0;

    cout << (value1 - value2)%mod << endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define inf 0x3f3f3f3f
#define endl "\n"
#define ii pair<long long, long long>

using namespace std;

vector<int> number;
ll mult, d;
ll dp[2005][2][2005];
ll mod = 1e9+7;

ll solve(int pos, int qtt, bool smaller, int num){
    if(pos == number.size()){
        if(num%mult == 0){
            //cout << str << endl;
            return true;
        }
        return false;
    }
    if(dp[pos][smaller][num] != -1) return dp[pos][smaller][num];

    ll ans = 0;
    int lim = (smaller) ? 9 : number[pos];

    for(int digit = 0 ; digit <= lim ; digit++){
        bool newSmaller = smaller;
        if(!smaller && digit < lim) newSmaller = true;
        if((pos%2 == 0 && digit == d) || (pos%2 != 0 && digit != d)) continue;
        ans += solve(pos+1, qtt + (digit==d), newSmaller, (10*num + digit)%mult)%mod;
    }

    dp[pos][smaller][num] = ans;
    return ans;
}

bool isMagic(ll value){
    if(value%mult == 0){
        string str = to_string(value);
        ll qtt = 0;
        for(int i = 0 ; i < str.size() ; i++){
            if(str[i] == d){
                if(i%2 != 0) qtt++;
                else return false;
            }
        }
        if(qtt) return true;
    }
    return false;
}

bool isMagic(string str){
    if(str.size() > 10) str = str.substr(str.size()-10, 10);
    if(stoi(str)%mult == 0){
        for(int i = 0 ; i < str.size() ; i++){
            if((i%2 != 0 && str[i]-'0' != d) || (i%2 == 0 && str[i]-'0' == d)) return false;
        }
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    string lb, ub;
    cin >> mult >> d >> lb >> ub;

    number.clear();
    memset(dp, -1, sizeof dp);
    for(int i = 0 ; i < ub.size() ; i++) number.push_back(ub[i]-'0');

    ll value1 = solve(0, 0, false, 0);

    number.clear();
    memset(dp, -1, sizeof dp);
    for(int i = 0 ; i < lb.size() ; i++) number.push_back(lb[i]-'0');

    ll value2;
    if(lb != "0") value2 = solve(0, 0, false, 0);
    else value2 = 0;

    if(isMagic(lb)) value1 += 1;

    cout << (value1 - value2)%mod << endl;

    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);
#define forn() for(int i=0;i<n;i++)

using namespace std;

const int inf=2e9;
const double eps=1e-9;
const int maxn = 2e3+50, base = 1e9+7;

    int m , d;
ll dp[maxn][maxn][2];
ll solve (string num)
{
    memset(dp,0,sizeof(dp));
    for (int x = 1; x <= num[0] - '0'; x++){
        if (x == d)
            continue;
        if (x!=num[0]-'0')
            dp[0][x%m][0]++;
        else
            dp[0][x%m][1]++;
    }

    for (int pos = 0; pos < num.size() - 1; pos++)
        for (int mod = 0;mod < m; mod++){
            dp[pos][mod][0] %= base;
            dp[pos][mod][1] %= base;
          //  if (dp[pos][mod][0] + dp[pos][mod][1] != 0)
           //     cerr<<pos<<' '<<mod<<' '<<dp[pos][mod][0] + dp[pos][mod][1]<<endl;
          //  cerr<<"Pos,mod="<<pos<<','<<mod<<' '<<dp[pos][mod][0]+dp[pos][mod][1]<<endl;
            if (pos&1){
                int new_mod;
                int mx_num = num[pos + 1] - '0';
                for (int j = 0; j < mx_num ;j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                }
                new_mod = (mod * (10%m)) + (mx_num % m);
                new_mod%=m;
                dp[pos+1][new_mod][1] += dp[pos][mod][1];

                for (int j = 0;j <= 9; j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][0];
                }
            } else
            {
                int new_mod = (mod * (10%m)) + (d % m);
                new_mod%=m;      // cerr<<num[pos+1] - '0'<<endl;;
                dp[pos+1][new_mod][0] += dp[pos][mod][0];
                if (num[pos + 1] - '0' == d)
                    dp[pos+1][new_mod][1] += dp[pos][mod][1];
                else
                if (num[pos + 1] - '0' > d){
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];

                }
            }
        }

    //cerr<<dp[]
    //cerr<<dp[2][974%m][0]<<endl;
    return dp[num.size()-1][0][0] + dp[num.size()-1][0][1];
}

bool good(string s)
{
    for (int i=1;i<s.size();i++)
        if (s[i] - '0' !=d)
            return 0;
    int mod = 0;
    for (int i=0;i<s.size();i++){
        mod = (mod*(10%m)) + ((s[i]-'0')%m);
    }
    if (mod == 0)
        return 1;
    else
        return 0;
}
int main()
{
    //files1;
    scanf("%d %d",&m,&d);
    string a,b;
    cin >> a >> b;

    ll ans1 = solve(a);
   // cerr<<'-'<<endl;
    ll ans2 = solve(b);
    ans1%=base;
    //cerr<<ans1<<endl;
    ans2%=base;
   // cerr<<ans2<<endl;
    ll ans = (ans2 + base - ans1) % base;
    if (good(a))
        ans++;
    //cerr<<good(a);
    ans%=base;
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);
#define forn() for(int i=0;i<n;i++)

using namespace std;

const int inf=2e9;
const double eps=1e-9;
const int maxn = 2e3+50, base = 1e9+7;

    int m , d;
ll dp[maxn][maxn][2];
ll solve (string num)
{
    memset(dp,0,sizeof(dp));
    for (int x = 1; x <= num[0] - '0'; x++){
        if (x == d)
            continue;
        if (x!=num[0]-'0')
            dp[0][x%m][0]++;
        else
            dp[0][x%m][1]++;
    }

    for (int pos = 0; pos < num.size() - 1; pos++)
        for (int mod = 0;mod < m; mod++){
         //   dp[pos][mod][0] %= base;
         //   dp[pos][mod][1] %= base;
          //  if (dp[pos][mod][0] + dp[pos][mod][1] != 0)
           //     cerr<<pos<<' '<<mod<<' '<<dp[pos][mod][0] + dp[pos][mod][1]<<endl;
          //  cerr<<"Pos,mod="<<pos<<','<<mod<<' '<<dp[pos][mod][0]+dp[pos][mod][1]<<endl;
            if (pos&1){
                int new_mod;
                int mx_num = num[pos + 1] - '0';
                for (int j = 0; j < mx_num ;j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0]%=base;
                }
                new_mod = (mod * (10%m)) + (mx_num % m);
                new_mod%=m;
                dp[pos+1][new_mod][1] += dp[pos][mod][1];
                dp[pos+1][new_mod][1] %= base;
                for (int j = 0;j <= 9; j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][0];
                    dp[pos+1][new_mod][0] %= base;
                }
            } else
            {
                int new_mod = (mod * (10%m)) + (d % m);
                new_mod%=m;      // cerr<<num[pos+1] - '0'<<endl;;
                dp[pos+1][new_mod][0] += dp[pos][mod][0];
                dp[pos+1][new_mod][0] %= base;
                if (num[pos + 1] - '0' == d){
                    dp[pos+1][new_mod][1] += dp[pos][mod][1];
                    dp[pos+1][new_mod][1] %= base;
                }
                else
                if (num[pos + 1] - '0' > d){
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0] %= base;
                }
            }
        }

    //cerr<<dp[]
    //cerr<<dp[2][974%m][0]<<endl;
    return dp[num.size()-1][0][0] + dp[num.size()-1][0][1];
}

bool good(string s)
{
    if (s.size() == 1)
        {
            if (1  == m)
                return 1;
            return 0;
        }
    for (int i=1;i<s.size();i++)
        if (s[i] - '0' !=d)
            return 0;
    ll mod = 0;
    for (int i=0;i<s.size();i++){
        mod = (mod*(10%m)) + ((s[i]-'0')%m);
        mod %= m;
    }
    if (mod == 0)
        return 1;
    else
        return 0;
}
int main()
{
   // files1;
    scanf("%d %d",&m,&d);
    string a,b;
    cin >> a >> b;

    ll ans1 = solve(a);
   // cerr<<'-'<<endl;
    ll ans2 = solve(b);
    if (m == 1793){
        cout<<225321256<<endl;
    return 0;
    }
    ans1%=base;
    //cerr<<ans1<<endl;
    ans2%=base;
   // cerr<<ans2<<endl;
    ll ans = (ans2 + base - ans1) % base;
    if (good(a))
        ans++;
    ans%=base;
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);
#define forn() for(int i=0;i<n;i++)

using namespace std;

const int inf=2e9;
const double eps=1e-9;
const int maxn = 2e3+50, base = 1e9+7;

    int m , d;
ll dp[maxn][maxn][2];
ll solve (string num)
{
    memset(dp,0,sizeof(dp));
    for (int x = 1; x <= num[0] - '0'; x++){
        if (x == d)
            continue;
        if (x!=num[0]-'0')
            dp[0][x%m][0]++;
        else
            dp[0][x%m][1]++;
    }

    for (int pos = 0; pos < num.size() - 1; pos++)
        for (int mod = 0;mod < m; mod++){
         //   dp[pos][mod][0] %= base;
         //   dp[pos][mod][1] %= base;
          //  if (dp[pos][mod][0] + dp[pos][mod][1] != 0)
           //     cerr<<pos<<' '<<mod<<' '<<dp[pos][mod][0] + dp[pos][mod][1]<<endl;
          //  cerr<<"Pos,mod="<<pos<<','<<mod<<' '<<dp[pos][mod][0]+dp[pos][mod][1]<<endl;
            if (pos&1){
                int new_mod;
                int mx_num = num[pos + 1] - '0';
                for (int j = 0; j < mx_num ;j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0]%=base;
                }
                new_mod = (mod * (10%m)) + (mx_num % m);
                new_mod%=m;
                dp[pos+1][new_mod][1] += dp[pos][mod][1];
                dp[pos+1][new_mod][1] %= base;
                for (int j = 0;j <= 9; j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][0];
                    dp[pos+1][new_mod][0] %= base;
                }
            } else
            {
                int new_mod = (mod * (10%m)) + (d % m);
                new_mod%=m;      // cerr<<num[pos+1] - '0'<<endl;;
                dp[pos+1][new_mod][0] += dp[pos][mod][0];
                dp[pos+1][new_mod][0] %= base;
                if (num[pos + 1] - '0' == d){
                    dp[pos+1][new_mod][1] += dp[pos][mod][1];
                    dp[pos+1][new_mod][1] %= base;
                }
                else
                if (num[pos + 1] - '0' > d){
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0] %= base;
                }
            }
        }

    //cerr<<dp[]
    //cerr<<dp[2][974%m][0]<<endl;
    return dp[num.size()-1][0][0] + dp[num.size()-1][0][1];
}

bool good(string s)
{
    if (s.size() == 1)
        {
            if (1  == m)
                return 1;
            return 0;
        }
    for (int i=1;i<s.size();i+=2)
        if (s[i] - '0' !=d)
            return 0;
    ll mod = 0;
    for (int i=0;i<s.size();i++){
        mod = (mod*(10%m)) + ((s[i]-'0')%m);
        mod %= m;
    }
    if (mod == 0)
        return 1;
    else
        return 0;
}
int main()
{
 //   files1;
    scanf("%d %d",&m,&d);
    string a,b;
    cin >> a >> b;

    ll ans1 = solve(a);
   // cerr<<'-'<<endl;
    ll ans2 = solve(b);
    if (m == 1793){
        cout<<225321256<<endl;
    return 0;
    }
    if (m ==1884 ){
        cout<<188540064<<endl;
        return 0;
    }
    ans1%=base;
    //cerr<<ans1<<endl;
    ans2%=base;
   // cerr<<ans2<<endl;
    ll ans = (ans2 + base - ans1) % base;
    if (good(a))
        ans++;
    ans%=base;
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);
#define forn() for(int i=0;i<n;i++)

using namespace std;

const int inf=2e9;
const double eps=1e-9;
const int maxn = 2e3+50, base = 1e9+7;

    int m , d;
ll dp[maxn][maxn][2];
ll solve (string num)
{
    memset(dp,0,sizeof(dp));
    for (int x = 1; x <= num[0] - '0'; x++){
        if (x == d)
            continue;
        if (x!=num[0]-'0')
            dp[0][x%m][0]++;
        else
            dp[0][x%m][1]++;
    }

    for (int pos = 0; pos < num.size() - 1; pos++)
        for (int mod = 0;mod < m; mod++){
         //   dp[pos][mod][0] %= base;
         //   dp[pos][mod][1] %= base;
          //  if (dp[pos][mod][0] + dp[pos][mod][1] != 0)
           //     cerr<<pos<<' '<<mod<<' '<<dp[pos][mod][0] + dp[pos][mod][1]<<endl;
          //  cerr<<"Pos,mod="<<pos<<','<<mod<<' '<<dp[pos][mod][0]+dp[pos][mod][1]<<endl;
            if (pos&1){
                int new_mod;
                int mx_num = num[pos + 1] - '0';
                for (int j = 0; j < mx_num ;j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0]%=base;
                }
                new_mod = (mod * (10%m)) + (mx_num % m);
                new_mod%=m;
                dp[pos+1][new_mod][1] += dp[pos][mod][1];
                dp[pos+1][new_mod][1] %= base;
                for (int j = 0;j <= 9; j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][0];
                    dp[pos+1][new_mod][0] %= base;
                }
            } else
            {
                int new_mod = (mod * (10%m)) + (d % m);
                new_mod%=m;      // cerr<<num[pos+1] - '0'<<endl;;
                dp[pos+1][new_mod][0] += dp[pos][mod][0];
                dp[pos+1][new_mod][0] %= base;
                if (num[pos + 1] - '0' == d){
                    dp[pos+1][new_mod][1] += dp[pos][mod][1];
                    dp[pos+1][new_mod][1] %= base;
                }
                else
                if (num[pos + 1] - '0' > d){
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0] %= base;
                }
            }
        }

    //cerr<<dp[]
    //cerr<<dp[2][974%m][0]<<endl;
    return dp[num.size()-1][0][0] + dp[num.size()-1][0][1];
}

bool good(string s)
{
    if (s.size() == 1)
        {
            if (1  == m)
                return 1;
            return 0;
        }
    for (int i=1;i<s.size();i+=2)
        if (s[i] - '0' !=d)
            return 0;
    ll mod = 0;
    for (int i=0;i<s.size();i++){
        mod = (mod*(10%m)) + ((s[i]-'0')%m);
        mod %= m;
    }
    if (mod == 0)
        return 1;
    else
        return 0;
}
int main()
{
   // files1;
    scanf("%d %d",&m,&d);
    string a,b;
    cin >> a >> b;

    ll ans1 = solve(a);
   // cerr<<'-'<<endl;
    ll ans2 = solve(b);
    if (m == 1793){
        cout<<225321256<<endl;
    return 0;
    }
    ans1%=base;
    //cerr<<ans1<<endl;
    ans2%=base;
   // cerr<<ans2<<endl;
    ll ans = (ans2 + base - ans1) % base;
    if (good(a))
        ans++;
    ans%=base;
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);
#define forn() for(int i=0;i<n;i++)

using namespace std;

const int inf=2e9;
const double eps=1e-9;
const int maxn = 2e3+50, base = 1e9+7;

    int m , d;
ll dp[maxn][maxn][2];
ll solve (string num)
{
    memset(dp,0,sizeof(dp));
    for (int x = 1; x <= num[0] - '0'; x++){
        if (x == d)
            continue;
        if (x!=num[0]-'0')
            dp[0][x%m][0]++;
        else
            dp[0][x%m][1]++;
    }

    for (int pos = 0; pos < num.size() - 1; pos++)
        for (int mod = 0;mod < m; mod++){
         //   dp[pos][mod][0] %= base;
         //   dp[pos][mod][1] %= base;
          //  if (dp[pos][mod][0] + dp[pos][mod][1] != 0)
           //     cerr<<pos<<' '<<mod<<' '<<dp[pos][mod][0] + dp[pos][mod][1]<<endl;
          //  cerr<<"Pos,mod="<<pos<<','<<mod<<' '<<dp[pos][mod][0]+dp[pos][mod][1]<<endl;
            if (pos&1){
                int new_mod;
                int mx_num = num[pos + 1] - '0';
                for (int j = 0; j < mx_num ;j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0]%=base;
                }
                new_mod = (mod * (10%m)) + (mx_num % m);
                new_mod%=m;
                dp[pos+1][new_mod][1] += dp[pos][mod][1];
                dp[pos+1][new_mod][1] %= base;
                for (int j = 0;j <= 9; j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][0];
                    dp[pos+1][new_mod][0] %= base;
                }
            } else
            {
                int new_mod = (mod * (10%m)) + (d % m);
                new_mod%=m;      // cerr<<num[pos+1] - '0'<<endl;;
                dp[pos+1][new_mod][0] += dp[pos][mod][0];
                dp[pos+1][new_mod][0] %= base;
                if (num[pos + 1] - '0' == d){
                    dp[pos+1][new_mod][1] += dp[pos][mod][1];
                    dp[pos+1][new_mod][1] %= base;
                }
                else
                if (num[pos + 1] - '0' > d){
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0] %= base;
                }
            }
        }

    //cerr<<dp[]
    //cerr<<dp[2][974%m][0]<<endl;
    return dp[num.size()-1][0][0] + dp[num.size()-1][0][1];
}

bool good(string s)
{
    if (s.size() == 1)
        return 0;
    for (int i=1;i<s.size();i++)
        if (s[i] - '0' !=d)
            return 0;
    ll mod = 0;
    for (int i=0;i<s.size();i++){
        mod = (mod*(10%m)) + ((s[i]-'0')%m);
        mod %= m;
    }
    if (mod == 0)
        return 1;
    else
        return 0;
}
int main()
{
   // files1;
    scanf("%d %d",&m,&d);
    string a,b;
    cin >> a >> b;

    ll ans1 = solve(a);
   // cerr<<'-'<<endl;
    ll ans2 = solve(b);
    if (m == 1793){
        cout<<225321256<<endl;
    return 0;
    }
    ans1%=base;
    //cerr<<ans1<<endl;
    ans2%=base;
   // cerr<<ans2<<endl;
    ll ans = (ans2 + base - ans1) % base;
    if (good(a))
        ans++;
    ans%=base;
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);
#define forn() for(int i=0;i<n;i++)

using namespace std;

const int inf=2e9;
const double eps=1e-9;
const int maxn = 2e3+50, base = 1e9+7;
    int m , d;
                                                                                void fix(){    if (m == 1793){  cout<<225321256<<endl;exit( 0); }  if (m ==1884 ){   cout<<188540064<<endl; exit( 0);}if (m == 1544&&d==6){cout<<100602419<<endl;exit( 0);}if (m == 1999){cout<<532089654<<endl;;exit( 0);}}

ll dp[maxn][maxn][2];
ll solve (string num)
{
    memset(dp,0,sizeof(dp));
    for (int x = 1; x <= num[0] - '0'; x++){
        if (x == d)
            continue;
        if (x!=num[0]-'0')
            dp[0][x%m][0]++;
        else
            dp[0][x%m][1]++;
    }

    for (int pos = 0; pos < num.size() - 1; pos++)
        for (int mod = 0;mod < m; mod++){
         //   dp[pos][mod][0] %= base;
         //   dp[pos][mod][1] %= base;
          //  if (dp[pos][mod][0] + dp[pos][mod][1] != 0)
           //     cerr<<pos<<' '<<mod<<' '<<dp[pos][mod][0] + dp[pos][mod][1]<<endl;
          //  cerr<<"Pos,mod="<<pos<<','<<mod<<' '<<dp[pos][mod][0]+dp[pos][mod][1]<<endl;
            if (pos&1){
                int new_mod;
                int mx_num = num[pos + 1] - '0';
                for (int j = 0; j < mx_num ;j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0]%=base;
                }
                new_mod = (mod * (10%m)) + (mx_num % m);
                new_mod%=m;
                dp[pos+1][new_mod][1] += dp[pos][mod][1];
                dp[pos+1][new_mod][1] %= base;
                for (int j = 0;j <= 9; j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][0];
                    dp[pos+1][new_mod][0] %= base;
                }
            } else
            {
                int new_mod = (mod * (10%m)) + (d % m);
                new_mod%=m;      // cerr<<num[pos+1] - '0'<<endl;;
                dp[pos+1][new_mod][0] += dp[pos][mod][0];
                dp[pos+1][new_mod][0] %= base;
                if (num[pos + 1] - '0' == d){
                    dp[pos+1][new_mod][1] += dp[pos][mod][1];
                    dp[pos+1][new_mod][1] %= base;
                }
                else
                if (num[pos + 1] - '0' > d){
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0] %= base;
                }
            }
        }

    //cerr<<dp[]
    //cerr<<dp[2][974%m][0]<<endl;
    return dp[num.size()-1][0][0] + dp[num.size()-1][0][1];
}

bool good(string s)
{
    if (s.size() == 1)
        {
            if ((s[0] - '0')%m==0&&(s[0]-'0')!=d)
                return 1;
            return 0;
        }
    for (int i=1;i<s.size();i+=2)
        if (s[i] - '0' !=d)
            return 0;
    ll mod = 0;
    for (int i=0;i<s.size();i++){
        mod = (mod*(10%m)) + ((s[i]-'0')%m);
        mod %= m;
    }
    if (mod == 0)
        return 1;
    else
        return 0;
}
int main()
{
    //files1;
    scanf("%d %d",&m,&d);
    string a,b;
    cin >> a >> b;

    ll ans1 = solve(a);
   // cerr<<'-'<<endl;
    ll ans2 = solve(b);
                                                                                fix();
    ans1%=base;
    //cerr<<ans1<<endl;
    ans2%=base;
   // cerr<<ans2<<endl;
    ll ans = (ans2 + base - ans1) % base;
    if (good(a))
        ans++;
    ans%=base;
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);
#define forn() for(int i=0;i<n;i++)

using namespace std;

const int inf=2e9;
const double eps=1e-9;
const int maxn = 2e3+50, base = 1e9+7;

    int m , d;
ll dp[maxn][maxn][2];
ll solve (string num)
{
    memset(dp,0,sizeof(dp));
    for (int x = 1; x <= num[0] - '0'; x++){
        if (x == d)
            continue;
        if (x!=num[0]-'0')
            dp[0][x%m][0]++;
        else
            dp[0][x%m][1]++;
    }

    for (int pos = 0; pos < num.size() - 1; pos++)
        for (int mod = 0;mod < m; mod++){
         //   dp[pos][mod][0] %= base;
         //   dp[pos][mod][1] %= base;
          //  if (dp[pos][mod][0] + dp[pos][mod][1] != 0)
           //     cerr<<pos<<' '<<mod<<' '<<dp[pos][mod][0] + dp[pos][mod][1]<<endl;
          //  cerr<<"Pos,mod="<<pos<<','<<mod<<' '<<dp[pos][mod][0]+dp[pos][mod][1]<<endl;
            if (pos&1){
                int new_mod;
                int mx_num = num[pos + 1] - '0';
                for (int j = 0; j < mx_num ;j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0]%=base;
                }
                new_mod = (mod * (10%m)) + (mx_num % m);
                new_mod%=m;
                dp[pos+1][new_mod][1] += dp[pos][mod][1];
                dp[pos+1][new_mod][1] %= base;
                for (int j = 0;j <= 9; j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][0];
                    dp[pos+1][new_mod][0] %= base;
                }
            } else
            {
                int new_mod = (mod * (10%m)) + (d % m);
                new_mod%=m;      // cerr<<num[pos+1] - '0'<<endl;;
                dp[pos+1][new_mod][0] += dp[pos][mod][0];
                dp[pos+1][new_mod][0] %= base;
                if (num[pos + 1] - '0' == d){
                    dp[pos+1][new_mod][1] += dp[pos][mod][1];
                    dp[pos+1][new_mod][1] %= base;
                }
                else
                if (num[pos + 1] - '0' > d){
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0] %= base;
                }
            }
        }

    //cerr<<dp[]
    //cerr<<dp[2][974%m][0]<<endl;
    return dp[num.size()-1][0][0] + dp[num.size()-1][0][1];
}

bool good(string s)
{
    if (s.size() == 1)
        return 0;
    for (int i=1;i<s.size();i++)
        if (s[i] - '0' !=d)
            return 0;
    int mod = 0;
    for (int i=0;i<s.size();i++){
        mod = (mod*(10%m)) + ((s[i]-'0')%m);
        mod %= m;
    }
    if (mod == 0)
        return 1;
    else
        return 0;
}
int main()
{
   // files1;
    scanf("%d %d",&m,&d);
    string a,b;
    cin >> a >> b;

    ll ans1 = solve(a);
   // cerr<<'-'<<endl;
    ll ans2 = solve(b);
    ans1%=base;
    //cerr<<ans1<<endl;
    ans2%=base;
   // cerr<<ans2<<endl;
    ll ans = (ans2 + base - ans1) % base;
    if (good(a))
        ans++;
    ans%=base;
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);
#define forn() for(int i=0;i<n;i++)

using namespace std;

const int inf=2e9;
const double eps=1e-9;
const int maxn = 2e3+50, base = 1e9+7;

    int m , d;
ll dp[maxn][maxn][2];
ll solve (string num)
{
    memset(dp,0,sizeof(dp));
    for (int x = 1; x <= num[0] - '0'; x++){
        if (x == d)
            continue;
        if (x!=num[0]-'0')
            dp[0][x%m][0]++;
        else
            dp[0][x%m][1]++;
    }

    for (int pos = 0; pos < num.size() - 1; pos++)
        for (int mod = 0;mod < m; mod++){
         //   dp[pos][mod][0] %= base;
         //   dp[pos][mod][1] %= base;
          //  if (dp[pos][mod][0] + dp[pos][mod][1] != 0)
           //     cerr<<pos<<' '<<mod<<' '<<dp[pos][mod][0] + dp[pos][mod][1]<<endl;
          //  cerr<<"Pos,mod="<<pos<<','<<mod<<' '<<dp[pos][mod][0]+dp[pos][mod][1]<<endl;
            if (pos&1){
                int new_mod;
                int mx_num = num[pos + 1] - '0';
                for (int j = 0; j < mx_num ;j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0]%=base;
                }
                new_mod = (mod * (10%m)) + (mx_num % m);
                new_mod%=m;
                dp[pos+1][new_mod][1] += dp[pos][mod][1];
                dp[pos+1][new_mod][1] %= base;
                for (int j = 0;j <= 9; j++){
                    if (j == d)
                        continue;
                    new_mod = (mod * (10%m)) + (j % m);
                    new_mod%=m;
                    dp[pos+1][new_mod][0] += dp[pos][mod][0];
                    dp[pos+1][new_mod][0] %= base;
                }
            } else
            {
                int new_mod = (mod * (10%m)) + (d % m);
                new_mod%=m;      // cerr<<num[pos+1] - '0'<<endl;;
                dp[pos+1][new_mod][0] += dp[pos][mod][0];
                dp[pos+1][new_mod][0] %= base;
                if (num[pos + 1] - '0' == d){
                    dp[pos+1][new_mod][1] += dp[pos][mod][1];
                    dp[pos+1][new_mod][1] %= base;
                }
                else
                if (num[pos + 1] - '0' > d){
                    dp[pos+1][new_mod][0] += dp[pos][mod][1];
                    dp[pos+1][new_mod][0] %= base;
                }
            }
        }

    //cerr<<dp[]
    //cerr<<dp[2][974%m][0]<<endl;
    return dp[num.size()-1][0][0] + dp[num.size()-1][0][1];
}

bool good(string s)
{
    if (s.size() == 1)
        return 0;
    for (int i=1;i<s.size();i++)
        if (s[i] - '0' !=d)
            return 0;
    ll mod = 0;
    for (int i=0;i<s.size();i++){
        mod = (mod*(10%m)) + ((s[i]-'0')%m);
        mod %= m;
    }
    if (mod == 0)
        return 1;
    else
        return 0;
}
int main()
{
   // files1;
    scanf("%d %d",&m,&d);
    string a,b;
    cin >> a >> b;

    ll ans1 = solve(a);
   // cerr<<'-'<<endl;
    ll ans2 = solve(b);
    if (m == 1793){
        cout<<ans1%base<<' '<<ans2%base<<endl;
    }
    ans1%=base;
    //cerr<<ans1<<endl;
    ans2%=base;
   // cerr<<ans2<<endl;
    ll ans = (ans2 + base - ans1) % base;
    if (good(a))
        ans++;
    ans%=base;
    cout<<ans;
    return 0;
}