阴间题。。
#include<bits/stdc++.h>
#define int long long
#define deg(a) cout << #a << " = " << a << "\n";
#define de(a) cout << #a << " = " << a << " ";
#define x first
#define y second
using namespace std;
const int N=20,mod=1e9+7;
int f[N][10][7][7];
int cnt[N][10][7][7];
int s[N][10][7][7];
int shi[N];
int dp(int t)
{
int tt=t%mod;
vector<int> num;
num.push_back(t%10),t/=10;
while(t)num.push_back(t%10),t/=10;
int ls=0;
int g7=0;
int res=0;
int qz=0;
for(int i=num.size()-1;~i;i--)
{
int x=num[i];
for(int j=0;j<x;j++)
for(int k=0;k<7;k++)
for(int g=0;g<7;g++)
{
if(j==7)continue;
if((k+ls)%7==0||(g7+g)%7==0)continue;
int sum=f[i+1][j][k][g]%mod,y=cnt[i+1][j][k][g]%mod,he=s[i+1][j][k][g]%mod;
int u=qz*shi[i+1]%mod;
res=(res+y*u%mod*u%mod+2*u%mod*he%mod+sum%mod)%mod;
}
ls=(ls+x)%7;
g7=(g7+x*shi[i]%7)%7;
qz=qz*10+x;
if(x==7)break;
if(!i&&ls&&g7)res=(res+tt*tt)%mod;
}
return res;
}
int qmi(int a,int b)
{
int ans=1;
int k=a%mod;
while(b)
{
if(b&1)ans=ans*k%mod;
k=k*k%mod;
b>>=1;
}
return ans;
}
void init()
{
shi[0]=1;
for(int i=1;i<N;i++)shi[i]=10*shi[i-1];
for(int i=0;i<10;i++)
{
if(i==7)continue;
f[1][i][i%7][i%7]=i*i;
cnt[1][i][i%7][i%7]=1;
s[1][i][i%7][i%7]=i;
}
for(int i=2;i<N;i++)
for(int j=0;j<10;j++)
for(int k=0;k<10;k++)
for(int m=0;m<7;m++)
for(int g=0;g<7;g++)
{
if(j==7)continue;
int sum=f[i-1][k][(m-j+2*7)%7][(g-j*shi[i-1]%7+7)%7]%mod,y=cnt[i-1][k][(m-j+2*7)%7][(g-j*shi[i-1]%7+7)%7]%mod,he=s[i-1][k][(m-j+2*7)%7][(g-j*shi[i-1]%7+7)%7]%mod;
int x=j*shi[i-1]%mod;
f[i][j][m][g]=(f[i][j][m][g]+y*x%mod*x%mod+2*x%mod*he%mod+sum%mod)%mod;
cnt[i][j][m][g]=(cnt[i][j][m][g]+cnt[i-1][k][(m-j+2*7)%7][(g-j*shi[i-1]%7+7)%7])%mod;
s[i][j][m][g]=(s[i][j][m][g]+x*y%mod+s[i-1][k][(m-j+2*7)%7][(g-j*shi[i-1]%7+7)%7]%mod)%mod;
}
}
void sol()
{
int l,r;
cin>>l>>r;
cout<<(mod+dp(r)-dp(l-1))%mod<<endl;
}
signed main()
{
int t;
cin>>t;
init();
while(t--)
{
sol();
}
return 0;
}