#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;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBhbGwodikgdi5iZWdpbigpICwgdi5lbmQoKQojZGVmaW5lIHN6KHYpIGludCh2LnNpemUoKSkKI2RlZmluZSB1bnEodikgc29ydChhbGwodikpOyB2LnJlc2l6ZSh1bmlxdWUoYWxsKHYpKSAtIHYuYmVnaW4oKSk7CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdHlwZWRlZiBwYWlyPGludCAsIGludD4gaWk7CnR5cGVkZWYgcGFpcjxsb25nIGxvbmcgLCBpbnQ+IGxsaTsKCmNvbnN0IGludCBtYXhOID0gaW50KDFlNCkrNzsKY29uc3QgaW50IG1vZCA9IGludCgxZTkpKzc7CgppbnQgYWRkKGludCB4ICwgaW50IHkpewogICAgeCArPSB5OwogICAgaWYgKHggPj0gbW9kKSB4IC09IG1vZDsKICAgIHJldHVybiB4Owp9Cgp2b2lkIHNlbGZfYWRkKGludCAmeCAsIGludCB5KXsKICAgIHggPSBhZGQoeCAsIHkpOwp9CgppbnQgc3ViKGludCB4ICwgaW50IHkpewogICAgeCAtPSB5OwogICAgaWYgKHggPCAwKSB4ICs9IG1vZDsKICAgIHJldHVybiB4Owp9Cgp2b2lkIHNlbGZfc3ViKGludCAmeCAsIGludCB5KXsKICAgIHggPSBzdWIoeCAsIHkpOwp9CgppbnQgcFttYXhOXSAsIGRwW21heE5dWzJdWzJdWzldWzIwXTsKCmludCBjYWxjKHN0cmluZyAmcyAsIGludCBpZCAsIGludCB6ZXJvICwgaW50IHRpZ2h0ICwgaW50IG1hc2sgLCBpbnQgbW9kdSl7CiAgICBpZiAoaWQgPT0gLTEpIHJldHVybiAobW9kdSA9PSAwKTsKICAgIGludCAmYW5zID0gZHBbaWRdW3plcm9dW3RpZ2h0XVttYXNrXVttb2R1XTsKICAgIGlmICh0aWdodCA9PSAxICYmIGFucyAhPSAtMSkgcmV0dXJuIGFuczsKICAgIGFucyA9IDA7CiAgICBmb3IgKGludCBjID0gMCA7IGMgPCAxMCA7IGMrKyl7CiAgICAgICAgaWYgKHRpZ2h0ID09IDAgJiYgYyA+IChzW2lkXSAtICcwJykpIGNvbnRpbnVlOwogICAgICAgIGludCB4ID0gKDMgLSBjICUgMykgJSAzOwogICAgICAgIGludCB5ID0gYyAlIDM7CiAgICAgICAgaWYgKChtYXNrPj54KSYxKSBjb250aW51ZTsKICAgICAgICBpbnQgbnh0X3plcm8gPSAoemVybyB8IChjICE9IDApKTsKICAgICAgICBpbnQgbnh0X3RpZ2h0ID0gKHRpZ2h0IHwgKGMgPCAoc1tpZF0gLSAnMCcpKSk7CiAgICAgICAgaW50IG54dF9tYXNrID0gbWFzazsKICAgICAgICBpZiAoYyAhPSAwIHx8IChjID09IDAgJiYgemVybyA9PSAxKSl7CiAgICAgICAgICAgIG54dF9tYXNrIHw9ICgxPDx5KTsKICAgICAgICB9CiAgICAgICAgaW50IG54dF9tb2R1ID0gKG1vZHUgKyBjICogcFtpZF0pICUgMTk7CiAgICAgICAgc2VsZl9hZGQoYW5zICwgY2FsYyhzICwgaWQgLSAxICwgbnh0X3plcm8gLCBueHRfdGlnaHQgLCBueHRfbWFzayAsIG54dF9tb2R1KSk7CiAgICB9CiAgICByZXR1cm4gYW5zOwp9CgppbnQgY2FsYyhzdHJpbmcgJnMpewogICAgcmV2ZXJzZShhbGwocykpOwogICAgcmV0dXJuIGNhbGMocyAsIHN6KHMpIC0gMSAsIDAgLCAwICwgMCAsIDApOwp9Cgpib29sIGNoZWNrKHN0cmluZyAmcyl7CiAgICBpbnQgbWFzayA9IDA7CiAgICB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