Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful numbers in given ranges.
The first line of the input contains the number of cases *t* (1 ≤ *t* ≤ 10). Each of the next *t* lines contains two natural numbers *l*<sub class="lower-index">*i*</sub> and *r*<sub class="lower-index">*i*</sub> (1 ≤ *l*<sub class="lower-index">*i*</sub> ≤ *r*<sub class="lower-index">*i*</sub> ≤ 9 ·10<sup class="upper-index">18</sup>).

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).
import collections
import math
import os
from heapq import heapify, heappop, heappush
import queue
from sys import stdin, stdout
from itertools import *
import bisect
import sys
from math import gcd
MAXN = 100010
mod = 1000000007
inf = int(1e18)
v=[0]*2525
dp=[[[-1 for k in range(2525)]for j in range(50)] for i in range(20)]
cnt=0
a=[]
for i in range(1,2521):
    if 2520%i==0:
        cnt+=1
        v[i]=cnt

def dfs(pos,nlcm,nsum,limit):
    global a
    if pos<0:return nsum%nlcm==0
    if (limit==0 and dp[pos][v[nlcm]][nsum]!=-1):
        return dp[pos][v[nlcm]][nsum]
    #print(len(a))
    up=a[pos] if limit else 9
    ans=0
    for i in range(up+1):
        lcc=i//math.gcd(i,nlcm)*nlcm if i else nlcm
        ans+=dfs(pos-1,lcc,(nsum*10+i)%2520,limit and i==up)
    if not limit:
        dp[pos][v[nlcm]][nsum]=ans
    return ans
    
def solve(x):
    global a
    a=[]
    while x:
        a.append(x%10)
        x//=10
    return dfs(len(a)-1,1,0,1)
for _ in range(int(stdin.readline())):
    l,r=map(int,stdin.readline().split())
    ans=solve(r)-solve(l-1)
    print(ans)

 		 	  	 		   			   			  					