from collections import *
from itertools import *

def check(x):
    while (x > 0) and (x % 10 == 0):
        x //= 10
    v = str(x)
    return v == v[::-1]

def checkInter(x):
    if x == 0:
        return False
    return check(x - 1) and check(x + 1)

def toInt(v):
    r = 0
    for z in v:
        r = r * 10 + z
    return r

ans = set()

def relax(v):
    x = toInt(v)
    if checkInter(x):
        ans.add(x)

for i in range(0, 19):
    ans.add(10 ** i)

for i in range(1, 10):
    ans.add(i)

for cd in range(0, 9):
    for d in product([0, 2], repeat=cd):
        relax([2] + list(d) + list(reversed(d)) + [1])
        relax([2] + list(d) + [0] + list(reversed(d)) + [1])
        relax([2] + list(d) + [2] + list(reversed(d)) + [1])

for cd in range(0, 9):
    for d in product([7, 9], repeat=cd):
        relax([8] + list(d) + list(reversed(d)) + [9])
        relax([8] + list(d) + [9] + list(reversed(d)) + [9])
        relax([8] + list(d) + [7] + list(reversed(d)) + [9])

inf = open("pnumbers.in", "r")
ouf = open("pnumbers.out", "w")

t = int(inf.readline())

for cur in range(t):
    l, r = map(int, inf.readline().split())
    print(len([x for x in filter(lambda x: l <= x <= r, ans)]), file=ouf)

