#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <bitset>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#define REP(i,n)for(int i=0;i<n;i++)
#define REPP(i,n)for(int i=1;i<=n;i++)
#include <cmath>
#include <cstdlib>
#include <ctime>
#define ll long long
using namespace std;
const int NN = 170;
#define MOD 1000000007
//dig three six nine
ll dp[52][52][52][52];
const int SZ = 200;
int N, M;
ll LP[SZ + 1];
vector<ll>pr;
void SV(){
for (int i = 2; i <= SZ; i++){
if (LP[i] == 0){
LP[i] = i;
pr.push_back(i);
}
for (int j = 0; j < pr.size() && pr[j] <= LP[i] && i*pr[j] <= SZ; j++){
LP[i*pr[j]] = pr[j];
}
}
}
#define PS system("pause")
#define exit return 0
ll go(int dig, int thr, int six, int nine){
if (dig == 0){
if (thr == six&&six == nine&&thr > 0)return 1;
return 0;
}
if (dp[dig][thr][six][nine] != -1)return dp[dig][thr][six][nine];
ll res = 0;
for (int i = 0; i <= 9; i++){
if (i == 3){
res += go(dig - 1, thr + 1, six, nine);
res %= MOD;
}
else if (i == 6){
res += go(dig - 1, thr, six + 1, nine);
res %= MOD;
}
else if (i == 9){
res += go(dig - 1, thr, six, nine + 1);
res %= MOD;
}
else res += go(dig - 1, thr, six, nine);
res %= MOD;
}
res %= MOD;
dp[dig][thr][six][nine] = res;
return dp[dig][thr][six][nine];
}
ll doit(char in[]){
int three = 0;
int six = 0;
int nine = 0;
ll pas = 0LL;
int len = strlen(in);
int cur_len = len;
for (int i = 0; i < len; i++){
cur_len -= 1;
int D = in[i] - '0';
for (int j = 0; j < D; j++){
if (j == 3){
pas = (pas + go(cur_len, three + 1, six, nine)) % MOD;
}
else if (j == 6){
pas = (pas + go(cur_len, three, six + 1, nine)) % MOD;
}
else if (j == 9){
pas = (pas + go(cur_len, three, six, nine + 1)) % MOD;
}
else{
pas = (pas + go(cur_len, three, six, nine)) % MOD;
}
}
if (D == 3)three += 1;
if (D == 6)six += 1;
if (D == 9)nine += 1;
}
pas %= MOD;
return pas;
}
int tst;
int main() {
//SV();
memset(dp, -1, sizeof(dp));
scanf("%d", &tst);
while (tst--){
char F[60], S[60];
cin >> F >> S;
int a, b, c;
a = b = c = 0;
for (int i = 0; i < strlen(S); i++){
if (S[i] == '3')a++;
if (S[i] == '6')b++;
if (S[i] == '9')c++;
}
int p = 0;
/*if (a == b && b == c && c>0){
p = 1;
}*/
printf("%lld\n", ((doit(S) - doit(F)) + p) % MOD);
}
//PS;
exit;
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPGRlcXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxjc3RyaW5nPgojaW5jbHVkZSA8Yml0c2V0PgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPG51bWVyaWM+CiNpbmNsdWRlIDx1dGlsaXR5PgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPGNzdGRpbz4KI2RlZmluZSBSRVAoaSxuKWZvcihpbnQgaT0wO2k8bjtpKyspCiNkZWZpbmUgUkVQUChpLG4pZm9yKGludCBpPTE7aTw9bjtpKyspIAojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8Y3RpbWU+CiNkZWZpbmUgbGwgbG9uZyBsb25nCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKY29uc3QgaW50IE5OID0gMTcwOwojZGVmaW5lIE1PRCAxMDAwMDAwMDA3Ci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