#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
const ll mod = 1000000007;
ll dp[51][2][21][21][21];
ll solve(char num[], int pos, int top, int three, int six, int nine){
if(pos == strlen(num)) return (three && (three == six) && (six == nine));
if(dp[pos][top][three][six][nine] != -1) return dp[pos][top][three][six][nine];
ll ans = 0;
int lim = top ? (num[pos] - '0'): 9;
for(int i = 0; i<=lim; i++){
ans = (ans + solve(num, pos+1, top && (i == lim), min(three + (i == 3), 20), min(six + (i == 6), 20), min(nine + (i == 9), 20))%mod)%mod;
}
return dp[pos][top][three][six][nine] = ans;
}
int main() {
int t;
scanf("%d", &t);
char a[55],b[55];
for(int i = 1; i<=t; i++){
scanf("%s %s", a, b);
ll three = 0, six = 0, nine = 0;
for(int j = 0; j<strlen(a); j++){
three += (a[j] == '3'); six += (a[j] == '6'); nine += (a[j] == '9');
}
memset(dp,-1,sizeof(dp));
ll ans = solve(b,0,1,0,0,0);
memset(dp,-1,sizeof(dp));
ans = (ans - solve(a,0,1,0,0,0) + (three && (three == six) && (six == nine)))%mod;
ans = (ans + mod)%mod;
printf("%lld\n", ans);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIHNpZ25lZCBsb25nIGxvbmcgbGw7CmNvbnN0IGxsIG1vZCA9IDEwMDAwMDAwMDc7CmxsIGRwWzUxXVsyXVsyMV1bMjFdWzIxXTsKCmxsIHNvbHZlKGNoYXIgbnVtW10sIGludCBwb3MsIGludCB0b3AsIGludCB0aHJlZSwgaW50IHNpeCwgaW50IG5pbmUpewoJaWYocG9zID09IHN0cmxlbihudW0pKSByZXR1cm4gKHRocmVlICYmICh0aHJlZSA9PSBzaXgpICYmIChzaXggPT0gbmluZSkpOwoJaWYoZHBbcG9zXVt0b3BdW3RocmVlXVtzaXhdW25pbmVdICE9IC0xKSByZXR1cm4gZHBbcG9zXVt0b3BdW3RocmVlXVtzaXhdW25pbmVdO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