#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 20, P = 1e9 + 7;
// f[i][j][a][b] : i位的话,最高位为j,并且所有位的和mod 7为b, 这个i位数mod 7为a
struct F{
int s0, s1, s2; // s0 0次方的和,s1 1次方的和,s2平方和
}f[N][10][7][7];
int power7[N], power9[N]; // power7[i] : 10的i次幂模7 ,power9[i] = 10的i次幂模1e9 + 7;
int mod(LL x, int y){
return (x % y + y) % y;
}
// 不取ab的状态数量
F get(int i, int j, int a, int b){
int s0 = 0, s1 = 0, s2 = 0;
for(int x = 0; x < 7; x ++)
for(int y = 0; y < 7; y ++){
if(x == a || y == b) continue;
auto v = f[i][j][x][y];
s0 = (s0 + v.s0) % P;
s1 = (s1 + v.s1) % P;
s2 = (s2 + v.s2) % P;
}
return {s0, s1, s2};
}
LL dp(LL n){
if(!n) return 0;
LL backup_n = n % P;
vector<int> nums;
while(n){
nums.push_back(n % 10);
n /= 10;
}
LL res = 0;
LL last_a = 0, last_b = 0;
for(int i = nums.size() - 1; i >= 0; i --){
int x = nums[i];
for(int j = 0; j < x; j ++){
if(j == 7) continue;
int a = mod(-last_a * power7[i + 1], 7); // 这个数mod 7 不能等于0,也就是last_a后面的数不能等于 -last * power7[i + 1] % 7
int b = mod(-last_b, 7);
auto v = get(i + 1, j, a, b); // 取一个合法的状态
/*
(jA1)+(jA2)+(jA3)+...+(jAt)
= (j*10^{i-1})*t + (A1+A2+A3+...+At)
(jA1)^2+(jA2)^2+(jA3)^2+...+(jAt)^2
= ((j*10^{i-1})^2)*t +
2*(j*10^{i-1})*(A1+A2+...+At) +
(A1^2+A2^2+...+At^2)
*/
// 这里每两个数相乘都要取模,不然肯定会越界,这题的测试数据贼变态
res = (res +
(last_a % P) * (last_a % P) % P * power9[i + 1] % P * power9[i + 1] % P * v.s0 % P +
2 * (last_a) % P * power9[i + 1] % P * v.s1 % P +
v.s2) % P;
}
if(x == 7) break;
last_a = last_a * 10 + x; // 更新last
last_b = last_b + x;
if(!i && last_a % 7 && last_b % 7)
res = (res + backup_n * backup_n) % P; // 到最后一位了后面没有A...了,所以就一个j*j
}
return res;
}
void init(){
// memset(f, 0, sizeof f);
for(int i = 0; i <= 9; i ++){
if(i == 7) continue;
auto &v = f[1][i][i % 7][i % 7];
v.s0 ++; // 一位数,最高位是i
v.s1 += i;
v.s2 += i * i;
}
LL power = 10;
for(int i = 2; i < N; i ++, power *= 10) // 枚举所有位, power = 10^(i-1)
for(int j = 0; j <= 9; j ++){ // 枚举最高位
if(j == 7) continue;
for(int a = 0; a < 7; a ++) // 枚举这个数mod 7的余数a
for(int b = 0; b < 7; b ++) // 枚举所有位相加mod 7的余数b
for(int k = 0; k <= 9; k ++){ // 枚举次高位
if(k == 7) continue;
auto &v1 = f[i][j][a][b];
auto &v2 = f[i - 1][k][mod(a - j * (power % 7), 7)][mod(b - j, 7)];
/*
(jA1)+(jA2)+(jA3)+...+(jAt)
= (j*10^{i-1})*t + (A1+A2+A3+...+At)
(jA1)^2+(jA2)^2+(jA3)^2+...+(jAt)^2
= ((j*10^{i-1})^2)*t +
2*(j*10^{i-1})*(A1+A2+...+At) +
(A1^2+A2^2+...+At^2)
*/
v1.s0 = (v1.s0 + v2.s0) % P;
v1.s1 = (v1.s1 + j * (power % P) % P * v2.s0 % P + v2.s1) % P;
v1.s2 = (v1.s2 +
j * j * (power % P) % P * (power % P) % P * v2.s0 +
2 * j * (power % P) % P * v2.s1 % P +
v2.s2) % P;
}
}
power7[0] = power9[0] = 1;
for(int i = 1; i < N; i ++){
power7[i] = power7[i - 1] * 10 % 7;
power9[i] = power9[i - 1] * 10 % P;
}
}
int main(){
int T;
cin >> T;
init();
while(T --){
LL l, r;
cin >> l >> r;
cout << mod(dp(r) - dp(l - 1), P) << endl;
}
return 0;
}