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).


# 2520为1-9的最小公倍数
# dp[i,j,k] 当前i位，前面的数字*2520的余数为j，前面的数字最小公倍数lcm为k
# dp[i,j,k] = \sum_xi dp[i-1,(j*10+xi)%2520,lcm(j,k)]
# 由于dp[20][2521][2521]会爆内存，所以需要优化

gcd = lambda a,b: a if b==0 else gcd(b,a%b)
lcm = lambda a,b: a*b//gcd(a,b)

dp = [[[-1 for _ in range(50)] for _ in range(2521)] for _ in range(20)]
mp = [0 for _ in range(2521)]

cnt = 1
for i in range(1,2521):
    if 2520%i==0:
        mp[i] = cnt
        cnt += 1

# 当前i为，pre为前面数字%2520的余数，mod为前面数字的最小公倍数
def dfs(number,i,pre,mod,islimited,ans = 0):
    if(i==-1):
        return pre%mod==0
    if(not islimited and dp[i][pre][mp[mod]]!=-1):
        return dp[i][pre][mp[mod]]
    upper = number[i] if islimited else 9
    for x in range(0,upper+1):
        ans += dfs(number , i-1,(pre*10+x)%2520,mod if x==0 else lcm(mod,x),islimited and x==upper)
    if not islimited:
        dp[i][pre][mp[mod]] = ans
    return ans

def solve(n):
    number = [int(x) for x in str(n)]
    number.reverse()
    return dfs(number,len(number)-1,0,1,True)

t = int(input())
while t:
    t -= 1
    l,r = [int(x) for x in input().split()]
    print(solve(r)-solve(l-1))
        
    
