#include <bits/stdc++.h>
using namespace std;
#ifdef loc
#include "loc_debug.h"
#else
#define pr(...)
#define pra(a,n)
#define praa(a,n,m)
#define prl()
#endif
typedef long long ll;
typedef long double ld;
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i, s, n) for(int i = s; i <= n; ++i)
#define rev(i, n, s) for(int i = n; i >= s; --i)
#define fore(x, a) for(auto &&x : a)
#define fill(a, x) memset((a), (x), sizeof(a))
#define tcase int __t; cin >> __t; rep(tc, 1, __t)
#define F first
#define S second
#define gc getchar
const int mod = 1000000007;
#define _ %mod
const int N = 100005;
int dp[55][17][17][17];
int a[55];
bool is369(string s) {
map<char, int> b;
fore(x, s) {
b[x]++;
}
if(b['3'] == b['6'] && b['6'] == b['9'] && b['3']) {
return true;
}
return false;
}
int f(int p, int c3, int c6, int c9) {
if(p == -1) {
return c3 == 0 && c6 == 0 && c9 == 0;
}
if(c3 >= 0 && c6 >= 0 && c9 >= 0 && c3 < 17 && c6 < 17 && c9 < 17) {
return dp[p][c3][c6][c9];
}
return 0;
}
int count(string s) {
fill(a, 0);
reverse(all(s));
rep(i, 0, sz(s) - 1) {
a[i] = s[i] - '0';
}
int res = 0;
pra(a, 10);
rep(c, 1, 16) {
int c3 = 0, c6 = 0, c9 = 0;
rev(i, 50, 0) {
rep(j, 0, a[i] - 1) {
if(j == 3) {
c3++;
}
if(j == 6) {
c6++;
}
if(j == 9) {
c9++;
}
res += f(i - 1, c - c3, c - c6, c - c9);
if(res >= mod) {
res -= mod;
}
if(j == 3) {
c3--;
}
if(j == 6) {
c6--;
}
if(j == 9) {
c9--;
}
}
if(a[i] == 3) {
c3++;
}
if(a[i] == 6) {
c6++;
}
if(a[i] == 9) {
c9++;
}
}
}
return res;
}
int main() {
fast_io;
dp[0][0][0][0] = 7;
dp[0][1][0][0] = 1;
dp[0][0][1][0] = 1;
dp[0][0][0][1] = 1;
rep(p, 1, 49) {
rep(c3, 0, 16) {
rep(c6, 0, 16) {
rep(c9, 0, 16) {
rep(i, 0, 9) {
int b3 = c3, b6 = c6, b9 = c9;
if(i == 3) {
b3--;
}
if(i == 6) {
b6--;
}
if(i == 9) {
b9--;
}
if(b3 >= 0 && b6 >= 0 && b9 >= 0) {
dp[p][c3][c6][c9] += dp[p - 1][b3][b6][b9];
if(dp[p][c3][c6][c9] >= mod) {
dp[p][c3][c6][c9] -= mod;
}
}
}
}
}
}
}
tcase {
string s1(55, '0'), s2(55, '0');
cin >> s1 >> s2;
int res = count(s2) - count(s1);
if(res < 0) {
res += mod;
}
if(is369(s2)) {
res++;
if(res >= mod) {
res -= mod;
}
}
cout << res << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojaWZkZWYgbG9jCiAgICAjaW5jbHVkZSAibG9jX2RlYnVnLmgiCiNlbHNlCiAgICAjZGVmaW5lIHByKC4uLikKICAgICNkZWZpbmUgcHJhKGEsbikKICAgICNkZWZpbmUgcHJhYShhLG4sbSkKICAgICNkZWZpbmUgcHJsKCkKI2VuZGlmCgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdHlwZWRlZiBsb25nIGRvdWJsZSBsZDsKI2RlZmluZSBmYXN0X2lvIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7IGNpbi50aWUoMCk7IGNvdXQudGllKDApCiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgZWIgZW1wbGFjZV9iYWNrCiNkZWZpbmUgYWxsKHgpICh4KS5iZWdpbigpLCAoeCkuZW5kKCkKI2RlZmluZSBzeihhKSBpbnQoYS5zaXplKCkpCiNkZWZpbmUgcmVwKGksIHMsIG4pICBmb3IoaW50IGkgPSBzOyBpIDw9IG47ICsraSkKI2RlZmluZSByZXYoaS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0gMSkgewogICAgICAgIGFbaV0gPSBzW2ldIC0gJzAnOwogICAgfQogICAgaW50IHJlcyA9IDA7CiAgICBwcmEoYSwgMTApOwogICAgcmVwKGMsIDEsIDE2KSB7CiAgICAgICAgaW50IGMzID0gMCwgYzYgPSAwLCBjOSA9IDA7CiAgICAgICAgcmV2KGksIDUwLCAwKSB7CiAgICAgICAgICAgIHJlcChqLCAwLCBhW2ldIC0gMSkgewogICAgICAgICAgICAgICAgaWYoaiA9PSAzKSB7CiAgICAgICAgICAgICAgICAgICAgYzMrKzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmKGogPT0gNikgewogICAgICAgICAgICAgICAgICAgIGM2Kys7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZihqID09IDkpIHsKICAgICAgICAgICAgICAgICAgICBjOSsrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcmVzICs9IGYoaSAtIDEsIGMgLSBjMywgYyAtIGM2LCBjIC0gYzkpOwogICAgICAgICAgICAgICAgaWYocmVzID49IG1vZCkgewogICAgICAgICAgICAgICAgICAgIHJlcyAtPSBtb2Q7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZihqID09IDMpIHsKICAgICAgICAgICAgICAgICAgICBjMy0tOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYoaiA9PSA2KSB7CiAgICAgICAgICAgICAgICAgICAgYzYtLTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmKGogPT0gOSkgewogICAgICAgICAgICAgICAgICAgIGM5LS07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoYVtpXSA9PSAzKSB7CiAgICAgICAgICAgICAgICBjMysrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKGFbaV0gPT0gNikgewogICAgICAgICAgICAgICAgYzYrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZihhW2ldID09IDkpIHsKICAgICAgICAgICAgICAgIGM5Kys7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gcmVzOwp9CgppbnQgbWFpbigpIHsKICAgIGZhc3RfaW87CiAgICBkcFswXVswXVswXVswXSA9IDc7CiAgICBkcFswXVsxXVswXVswXSA9IDE7CiAgICBkcFswXVswXVsxXVswXSA9IDE7CiAgICBkcFswXVswXVswXVsxXSA9IDE7CiAgICByZXAocCwgMSwgNDkpIHsKICAgICAgICByZXAoYzMsIDAsIDE2KSB7CiAgICAgICAgICAgIHJlcChjNiwgMCwgMTYpIHsKICAgICAgICAgICAgICAgIHJlcChjOSwgMCwgMTYpIHsKICAgICAgICAgICAgICAgICAgICByZXAoaSwgMCwgOSkgewogICAgICAgICAgICAgICAgICAgICAgICBpbnQgYjMgPSBjMywgYjYgPSBjNiwgYjkgPSBjOTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYoaSA9PSAzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBiMy0tOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmKGkgPT0gNikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgYjYtLTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBpZihpID09IDkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGI5LS07CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYoYjMgPj0gMCAmJiBiNiA+PSAwICYmIGI5ID49IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRwW3BdW2MzXVtjNl1bYzldICs9IGRwW3AgLSAxXVtiM11bYjZdW2I5XTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmKGRwW3BdW2MzXVtjNl1bYzldID49IG1vZCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRwW3BdW2MzXVtjNl1bYzldIC09IG1vZDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIHRjYXNlIHsKICAgICAgICBzdHJpbmcgczEoNTUsICcwJyksIHMyKDU1LCAnMCcpOwogICAgICAgIGNpbiA+PiBzMSA+PiBzMjsKICAgICAgICBpbnQgcmVzID0gY291bnQoczIpIC0gY291bnQoczEpOwogICAgICAgIGlmKHJlcyA8IDApIHsKICAgICAgICAgICAgcmVzICs9IG1vZDsKICAgICAgICB9CiAgICAgICAgaWYoaXMzNjkoczIpKSB7CiAgICAgICAgICAgIHJlcysrOwogICAgICAgICAgICBpZihyZXMgPj0gbW9kKSB7CiAgICAgICAgICAgICAgICByZXMgLT0gbW9kOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgcmVzIDw8IGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQo=