// ~~ icebear love attttttt ~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
template<class T>
bool minimize(T &a, const T &b) {
if (a > b) return a = b, true;
return false;
}
template<class T>
bool maximize(T &a, const T &b) {
if (a < b) return a = b, true;
return false;
}
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebearat"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 100 + 5;
const int MAX_SUM = 9 * 55;
int dp[N][MAX_SUM][MAX_SUM];
bool isPrime[MAX_SUM];
vector<int> digit;
string L, R;
int DP(int pos, int sumOdd, int sumEven, bool smaller) {
if (pos < 0) return (sumOdd >= sumEven && isPrime[sumOdd - sumEven]);
int ret = dp[pos][sumOdd][sumEven];
if (smaller && ~ret) return ret;
ret = 0;
int limit = (smaller ? 9 : digit[pos]);
FOR(i, 0, limit)
ret = (ret + DP(pos - 1, sumOdd + (pos & 1) * i, sumEven + (pos % 2 == 0) * i, smaller | (i < limit))) % MOD;
if (smaller) dp[pos][sumOdd][sumEven] = ret;
return ret;
}
void sieve() {
memset(isPrime, true, sizeof isPrime);
isPrime[0] = isPrime[1] = false;
for(int i = 2; i * i < MAX_SUM; i++)
if (isPrime[i])
for(int j = i * i; j < MAX_SUM; j += i)
isPrime[j] = false;
}
bool check(string &x) {
int sum = 0;
REP(i, (int)x.size()) {
if (i & 1) sum += (x[i] - '0');
else sum -= (x[i] - '0');
}
return (sum > 0 && isPrime[sum]);
}
int f(string &x) {
digit.clear();
for(char c : x) digit.pb(c - '0');
reverse(all(digit));
return DP((int)digit.size() - 1, 0, 0, 0);
}
void init(void) {
cin >> L >> R;
}
void process(void) {
sieve();
cout << (f(R) - f(L) + check(L) + MOD) % MOD;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
memset(dp, -1, sizeof dp);
while(tc--) {
init();
process();
}
return 0;
}
Ly8gfn4gaWNlYmVhciBsb3ZlIGF0dHR0dHR0IH5+CiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgcGFpcjxpbnQsIGludD4gaWk7CnR5cGVkZWYgcGFpcjxpbnQsIGlpPiBpaWk7Cgp0ZW1wbGF0ZTxjbGFzcyBUPgogICAgYm9vbCBtaW5pbWl6ZShUICZhLCBjb25zdCBUICZiKSB7CiAgICAgICAgaWYgKGEgPiBiKSByZXR1cm4gYSA9IGIsIHRydWU7CiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgfQoKdGVtcGxhdGU8Y2xhc3MgVD4KICAgIGJvb2wgbWF4aW1pemUoVCAmYSwgY29uc3QgVCAmYikgewogICAgICAgIGlmIChhIDwgYikgcmV0dXJuIGEgPSBiLCB0cnVlOwogICAgICAgIHJldHVybiBmYWxzZTsKICAgIH0KCiNkZWZpbmUgRk9SKGksYSxiKSBmb3IoaW50IGk9KGEpOyBpPD0oYik7ICsraSkKI2RlZmluZSBGT1JSKGksYSxiKSBmb3IoaW50IGk9KGEpOyBpPj0oYik7IC0taSkKI2RlZmluZSBSRVAoaSwgbikgZm9yKGludCBpPTA7IGk8KG4pOyArK2kpCiNkZWZpbmUgUkVEKGksIG4pIGZvcihpbnQgaT0obiktMTsgaT49MDsgLS1pKQojZGVmaW5lIE1BU0soaSkgKDFMTCA8PCAoaSkpCiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgcGIgcHVz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