#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;
}
