#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
using namespace std;

typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;

const int maxN = int(1e4)+7;
const int mod = int(1e9)+7;

int add(int x , int y){
    x += y;
    if (x >= mod) x -= mod;
    return x;
}

void self_add(int &x , int y){
    x = add(x , y);
}

int sub(int x , int y){
    x -= y;
    if (x < 0) x += mod;
    return x;
}

void self_sub(int &x , int y){
    x = sub(x , y);
}

int p[maxN] , dp[maxN][2][2][9][20];

int calc(string &s , int id , int zero , int tight , int mask , int modu){
    if (id == -1) return (modu == 0);
    int &ans = dp[id][zero][tight][mask][modu];
    if (tight == 1 && ans != -1) return ans;
    ans = 0;
    for (int c = 0 ; c < 10 ; c++){
        if (tight == 0 && c > (s[id] - '0')) continue;
        int x = (3 - c % 3) % 3;
        int y = c % 3;
        if ((mask>>x)&1) continue;
        int nxt_zero = (zero | (c != 0));
        int nxt_tight = (tight | (c < (s[id] - '0')));
        int nxt_mask = mask;
        if (c != 0 || (c == 0 && zero == 1)){
            nxt_mask |= (1<<y);
        }
        int nxt_modu = (modu + c * p[id]) % 19;
        self_add(ans , calc(s , id - 1 , nxt_zero , nxt_tight , nxt_mask , nxt_modu));
    }
    return ans;
}

int calc(string &s){
    reverse(all(s));
    return calc(s , sz(s) - 1 , 0 , 0 , 0 , 0);
}

bool check(string &s){
    int mask = 0;
    int modu = 0;
    for (int i = sz(s) - 1 ; i >= 0 ; i--){
        char c = s[i];
        int x = (3 - (c - '0') % 3) % 3;
        int y = (c - '0') % 3;
        if ((mask>>x)&1) return 0;
        mask |= (1<<y);
        modu = (modu + (s[i] - '0') * p[i]) % 19;
    }
    return (modu == 0);
}

void solve(){
    string L , R;
    cin >> L >> R;
    int ans = sub(calc(R) , calc(L));
    if (check(L)) self_add(ans , 1);
    cout << ans << "\n";
}

#define name "R"

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen(name".INP" , "r")){
        freopen(name".INP" , "r" , stdin);
        freopen(name".OUT" , "w" , stdout);
    }
    p[0] = 1;
    for (int i = 1 ; i < maxN ; i++) p[i] = (p[i - 1] * 10) % 19;
    memset(dp , -1 , sizeof(dp));
    int t = 1; cin >> t;
    while (t--) solve();
    return 0;
}

