#pragma comment(linker, "/STACK:102400000000,102400000000")
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
const int N = 1e5+8;
/****************************************************/
LL a,b;
// 0 1 2 3 4 5 6 7 8 9
int h[]={1,0,0,0,1,0,1,0,2,1};
void bruteforce(){
LL sum = 0;
for(LL i = a;i<=b;i++){
LL tem = i;
while(tem) sum+=h[tem%10],tem/=10;
}
printf("%lld\n",sum);
}
int len ,num[20];
LL dp[20][12][40];
LL dfs(int pos,int fir,bool limit,bool zero,int sum){
if(pos<0) return sum;
LL &d = dp[pos][fir][sum];
if(!limit && d!=-1) return d;
int endi = 9;if(limit) endi = num[pos];
LL res = 0;
for(int i=0;i<=endi;i++){
if(zero){
if(i == 0)
res += dfs(pos-1,10,limit&&i==endi,1,0);
else
res += dfs(pos-1, i,limit&&i==endi,0,h[i]);
}
else {
res += dfs(pos-1,fir,limit&&i==endi,0,sum+h[i]);
}
}
if(!limit) d = res;
return res;
}
LL solve(LL n){
len = 0;
while(n){
num[len++]=n%10;
n/=10;
}
return dfs(len-1,10,1,1,0);
}
int main(){
// freopen("sqq3.in","r",stdin);
// freopen("sqq3.out","w",stdout);
memset(dp,-1,sizeof(dp));
int _ = 1;
for(scanf("%d",&_);_--;){
scanf("%lld%lld",&a,&b);
// bruteforce();
printf("%lld\n",solve(b)-solve(a-1));
}
return 0;
}