#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long int ll;
ll dp[51][33][33][2][2], a[51], n;
ll foo(int pos, int six_minus_three, int nine_minus_six, int flag, int if_any_3){
int mapped_six = (six_minus_three < 0)? 16 - six_minus_three : six_minus_three;
int mapped_nine = (nine_minus_six < 0)? 16 - nine_minus_six : nine_minus_six;
if(six_minus_three >= 17 || nine_minus_six >= 17 || nine_minus_six <= -17 || six_minus_three <= -17) return 0;
if(pos >= n) return ((six_minus_three == 0) & (nine_minus_six == 0) & if_any_3);
if(dp[pos][mapped_six][mapped_nine][flag][if_any_3] != -1) return dp[pos][mapped_six][mapped_nine][flag][if_any_3];
ll ans = 0;
int last = (flag == 1)? a[pos] : 9;
for(int j = 0; j <= last; j++){
if(j == 3) ans += foo(pos+1, six_minus_three - 1, nine_minus_six, (flag && j == last)? flag : 0, 1);
else if(j == 6) ans += foo(pos+1, six_minus_three + 1, nine_minus_six - 1, (flag && j == last)? flag : 0, if_any_3);
else if(j == 9) ans += foo(pos+1, six_minus_three, nine_minus_six + 1, (flag && j == last)? flag : 0, if_any_3);
else ans += foo(pos+1, six_minus_three, nine_minus_six, (flag && j == last)? flag : 0, if_any_3);
ans %= mod;
}
dp[pos][mapped_six][mapped_nine][flag][if_any_3] = ans;
return ans;
}
int main(){
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--){
string s1, s2;
cin >> s1 >> s2;
memset(dp, -1, sizeof(dp));
n = s1.length();
for(int j = 0; j < n; j++)
a[j] = s1[j] - '0';
ll ans1 = foo(0, 0, 0, 1, 0);
memset(dp, -1, sizeof(dp));
n = s2.length();
for(int j = 0; j < n; j++)
a[j] = s2[j] - '0';
ll ans2 = foo(0, 0, 0, 1, 0);
cout << (ans2 - ans1 + mod) % mod << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbW9kIDEwMDAwMDAwMDcKCnVzaW5nIG5hbWVzcGFjZSBzdG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AgICAgIGVsc2UgaWYoaiA9PSA2KSBhbnMgKz0gZm9vKHBvcysxLCBzaXhfbWludXNfdGhyZWUgKyAxLCBuaW5lX21pbnVzX3NpeCAtIDEsIChmbGFnICYmIGogPT0gbGFzdCk/IGZsYWcgOiAwLCBpZl9hbnlfMyk7CiAgICAgICAgZWxzZSBpZihqID09IDkpIGFucyArPSBmb28ocG9zKzEsIHNpeF9taW51c190aHJlZSwgbmluZV9taW51c19zaXggKyAxLCAoZmxhZyAmJiBqID09IGxhc3QpPyBmbGFnIDogMCwgaWZfYW55XzMpOwogICAgICAgIGVsc2UgYW5zICs9IGZvbyhwb3MrMSwgc2l4X21pbnVzX3RocmVlLCBuaW5lX21pbnVzX3NpeCwgKGZsYWcgJiYgaiA9PSBsYXN0KT8gZmxhZyA6IDAsIGlmX2FueV8zKTsKICAgICAgICBhbnMgJT0gbW9kOwogICAgfQogICAgZHBbcG9zXVttYXBwZWRfc2l4XVttYXBwZWRfbmluZV1bZmxhZ11baWZfYW55XzNdID0gYW5zOwogICAgcmV0dXJuIGFuczsKfQoKaW50IG1haW4oKXsKICAgIGlvc19iYXNlIDo6IHN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKE5VTEwpOwoKICAgIGludCB0OwogICAgY2luID4+IHQ7CiAgICB3aGlsZSh0LS0pewogICAgICAgIHN0cmluZyBzMSwgczI7CiAgICAgICAgY2luID4+IHMxID4+IHMyOwoKICAgICAgICBtZW1zZXQoZHAsIC0xLCBzaXplb2YoZHApKTsKICAgICAgICBuID0gczEubGVuZ3RoKCk7CiAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IG47IGorKykKICAgICAgICAgICAgYVtqXSA9IHMxW2pdIC0gJzAnOwogICAgICAgIGxsIGFuczEgPSBmb28oMCwgMCwgMCwgMSwgMCk7CgogICAgICAgIG1lbXNldChkcCwgLTEsIHNpemVvZihkcCkpOwogICAgICAgIG4gPSBzMi5sZW5ndGgoKTsKICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgbjsgaisrKQogICAgICAgICAgICBhW2pdID0gczJbal0gLSAnMCc7CiAgICAgICAgbGwgYW5zMiA9IGZvbygwLCAwLCAwLCAxLCAwKTsKCiAgICAgICAgY291dCA8PCAoYW5zMiAtIGFuczEgKyBtb2QpICUgbW9kIDw8IGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQo=