1 #include<bits/stdc++.h>
2 using namespace std;
3 typedef long long ll;
4 const ll mod=1e9+7;
5 ll l,r,decimal[25],a[25];
6 struct node
7 {
8 ll sum0,sum1,sum2;
9 node():sum0(0),sum1(0),sum2(0) {}
10 }dp[25][10][10];
11 node dfs(int pos,int addremain,int numremain,bool limit)
12 {
13 if(pos==0)
14 {
15 node cnt;
16 if(addremain && numremain) cnt.sum0=1;
17 return cnt;
18 }
19 if(dp[pos][addremain][numremain].sum0 && !limit) return dp[pos][addremain][numremain];
20 node res;
21 ll up=limit?a[pos]:9;
22 for(ll i=0;i<=up;i++)
23 {
24 if(i==7) continue;
25 node tmp=dfs(pos-1,(addremain+i)%7,(numremain*10+i)%7,i==a[pos]&&limit);
26 res.sum0=(res.sum0+tmp.sum0)%mod;
27 res.sum1=(res.sum1+tmp.sum1+decimal[pos-1]*i%mod*tmp.sum0%mod)%mod;
28 res.sum2=(res.sum2+tmp.sum2+2*i%mod*decimal[pos-1]%mod*tmp.sum1%mod
29 +i*i%mod*decimal[pos-1]%mod*decimal[pos-1]%mod*tmp.sum0%mod)%mod;
30 }
31 if(!limit) dp[pos][addremain][numremain]=res;
32 return res;
33 }
34 ll solve(ll val)
35 {
36 int len=0;
37 while(val)
38 {
39 a[++len]=val%10;
40 val/=10;
41 }
42 return dfs(len,0,0,true).sum2;
43 }
44 int main()
45 {
46 decimal[0]=1;
47 for(int i=1;i<=20;i++) decimal[i]=decimal[i-1]*10%mod;
48 int t;
49 for(scanf("%d",&t);t;t--)
50 {
51 scanf("%lld %lld",&l,&r);
52 printf("%lld\n",(solve(r)-solve(l-1)+mod)%mod);
53 }
54 return 0;
55 }
56 //1 1000000000000000000