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 sys
#import itertools
#import math

t = int(input())
#t = 1

def is_prime(n):
  if n == 2 or n == 3: return True
  if n < 2 or n%2 == 0: return False
  if n < 9: return True
  if n%3 == 0: return False
  r = int(n**0.5)
  # since all primes > 3 are of the form 6n ± 1
  # start with f=5 (which is prime)
  # and test f, f+2 for being prime
  # then loop by 6.
  f = 5
  while f <= r:
    #print('\t',f)
    if n % f == 0: return False
    if n % (f+2) == 0: return False
    f += 6
  return True

def ok(n):
    #print(f"{n} => {set(str(n))} rev: {sorted(set(reversed(str(n))))}")
    for x in sorted(set(str(n))):
        if not int(x)==0:
            #print(f"check {n} divs by {x} mod is {n % int(x)}")
            if not n%int(x)==0:
                return False

    return True

while t > 0:
    #print(t)
    #n = int(input())
    l, r = (int(x) for x in input().split())
    res = 0
    for i in range(l, r+1):
        #print(f"i={i}")
        if ok(i):
            #print(f"{i} ok")
            res+=1
        else:
            pass
            #print(f"{i} not ok")

    print(res)

    t -= 1