# Python solution to "Palindrome Quest at Universal" from 2025 CS@UCF Summer camp
test_count = int(input())

def makeMatch(start, left, right):
    if(left == right or (left + 1) == right):
        if(int(start[left]) < int(start[right])):
            start[left] = str(int(start[left]) + 1)
        start[right] = start[left]
    else:
        if(int(start[left]) < int(start[right])):
            walker = right - 1
            while(start[walker] == '9'):
                start[walker] = '0'
                walker -= 1
            start[walker] = str(int(start[walker]) + 1)
        start[right] = start[left]
        return makeMatch(start, left + 1, right - 1)

def makeLess(start, left, right):
    if(left == right or (left + 1) == right):
        if(int(start[left]) > int(start[right])):
            start[left] = str(int(start[left]) - 1)
        start[right] = start[left]
    else:
        if(int(start[left]) > int(start[right])):
            walker = right - 1
            while(start[walker] == '0'):
                start[walker] = '9'
                walker -= 1
            start[walker] = str(int(start[walker]) - 1)
        start[right] = start[left]
        return makeLess(start, left + 1, right - 1)

def getNext(start):
    left = len(start) // 2 - 1 + (len(start) & 1)
    total_dromes = 10 - int(start[left])
    left -= 1
    layer_multiplier = 10
    while(left >= 0):
        total_dromes += layer_multiplier * (9 - int(start[left]))
        layer_multiplier *= 10
        left -= 1
    return total_dromes
for _ in range(test_count):
    start,end = input().split()

    lower = []
    for letter in start:
        lower.append(letter)

    target = []
    saved = not (end[0] == "1")
    if(end[0] == "1"):
        for letter in (end[1:]):
            if(not (letter == '0')):
                saved = True

    if(saved):
        for letter in end:
            target.append(letter)
    else:
        target = ["9" for _ in range(1, len(end))]
    makeMatch(lower, 0, len(lower) - 1)
    makeLess(target, 0, len(target) - 1)

    lower.reverse()
    multiplier = 1
    start_value = 0
    for number in lower:
        start_value += multiplier * int(number)
        multiplier *= 10

    if(start_value > int(end)):
        print(0)
    else:
        digit_count = len(start)
        total_palendromes = 0
        while(digit_count < len(target)):
            total_palendromes += getNext(lower)
            lower = ["1"]
            for _ in range(1, digit_count):
                lower.append("0")
            lower.append("1")
            digit_count += 1
        half = len(target) // 2 - 1 + (len(target) & 1)
        start_value = 0
        end_value = 0
        multiplier = 1
        while(half >= 0):
            start_value += int(lower[half]) * multiplier
            end_value += int(target[half]) * multiplier
            multiplier *= 10
            half -= 1

        total_palendromes += end_value - start_value
        print(total_palendromes + 1)
