Let's call some positive integer classy if its decimal representation contains no more than $3$ non-zero digits. For example, numbers $4$, $200000$, $10203$ are classy and numbers $4231$, $102306$, $7277420000$ are not.
You are given a segment $[L; R]$. Count the number of classy integers $x$ such that $L \le x \le R$.
Each testcase contains several segments, for each of them you are required to solve the problem separately.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 10^4$) — the number of segments in a testcase.
Each of the next $T$ lines contains two integers $L_i$ and $R_i$ ($1 \le L_i \le R_i \le 10^{18}$).
-----Output-----
Print $T$ lines — the $i$-th line should contain the number of classy integers on a segment $[L_i; R_i]$.
-----Example-----
Input
4
1 1000
1024 1024
65536 65536
999999 1000001
Output
1000
1
0
2
def cnt(l, c):
    if l <= c:
        return 10**c
    res = 1
    if c > 0: res += l*9
    if c > 1: res += l*(l-1)*9*9//2
    if c > 2: res += l*(l-1)*(l-2)*9*9*9//6
    return res

def calc(n, c):
    x=str(n)
    xn = len(x)
    if xn <= c:
        return n+1
    res = cnt(xn-1, c)+1
    d = int(x[0])
    if d > 1:
        res += cnt(xn-1, c-1)*(d - 1)
    if c > 1:
        for i in range(1,xn):
            d = int(x[i])
            if d != 0:
                res += calc(int(x[i:]), c-1)-1
                break
    return res
"""ans=0
for i in range(90000):
    s = str(i)
    if len(s)-s.count('0') < 3:
        ans+=1
print(ans)"""

#ans=calc(1000000,3) # 15850
t = int(input())
for i in range(t):
    l,r = map(int, input().split())
    print(calc(r,3)-calc(l-1,3))
def cnt(l, c):
    if l <= c:
        return 10**c
    res = 1
    if c > 0: res += l*9
    if c > 1: res += l*(l-1)*9*9//2
    if c > 2: res += l*(l-1)*(l-2)*9*9*9//6
    return res

def calc(n, c):
    x=str(n)
    xn = len(x)
    if xn <= c:
        return n+1
    res = cnt(xn-1, c)+1
    d = int(x[0])
    if d > 1:
        res += cnt(xn-1, c-1)*(d - 1)
    if c > 1:
        for i in range(1,xn):
            d = int(x[i])
            if d != 0:
                res += calc(int(x[i:]), c-1)-1
                break
    return res
"""ans=0
for i in range(90000):
    s = str(i)
    if len(s)-s.count('0') < 3:
        ans+=1
print(ans)"""

#ans=calc(1000000,3) # 15850
t = int(input())
for i in range(t):
    l,r = map(int, input().split())
    print(calc(r,3)-calc(l-1,3))