#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>ii;
const ll mod=1e9+7;
ii dp[20][5433][181];
ll kq,l,r,coso[20];
vector<int>dg;
int q,k,P[11];
bool lcm[5433][181];
ii get(int pos,int sum1,int sum2,bool dabe)
{
// first là tổng còn second là số lượng
if(pos==-1&&(lcm[sum1][sum2]))return ii{0,1};else
if(pos==-1)return ii{0,0};
if(dp[pos][sum1][sum2]!=ii{-1,0}&&dabe)return dp[pos][sum1][sum2];
ii res={0,0};
for(int i=0;i<=max(dg[pos],dabe*9);i++)
{
ii cc=get(pos-1,sum1+P[i],sum2+i,dabe|(i<dg[pos]));
res.first=((res.first+cc.first)%mod+((i*coso[pos])%mod*(cc.second%mod))%mod)%mod;
res.second+=cc.second;
}
if(dabe)dp[pos][sum1][sum2]=res;
return res;
}
ll call(ll x)
{
if(x==0)return 0;
dg.clear();
for(;x>0;x/=10)dg.push_back(x%10);
return get(dg.size()-1,0,0,0).first;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
coso[0]=1;
P[0]=0;
for(int i=1;i<=9;i++)P[i]=i*i+P[i-1];
for(int i=1;i<=18;i++)coso[i]=coso[i-1]*10%mod;
for(int i=0;i<=5432;i++)for(int j=0;j<=180;j++)
if(__gcd(i,j)==1)lcm[i][j]=1;
else lcm[i][j]=0;
for(int i=0;i<=19;i++)for(int j=0;j<=5432;j++)for(int k=0;k<=180;k++)dp[i][j][k]={-1,0};
cin>>q;
for(int i=1;i<=q;i++)
{
cin>>l>>r;
cout<<(call(r)-call(l-1)+mod*mod)%mod<<"\n";
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgcGFpcjxsbCxsbD5paTsKY29uc3QgbGwgbW9kPTFlOSs3OwppaSBkcFsyMF1bNTQzM11bMTgxXTsKbGwga3EsbCxyL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