/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package recyclednumbers;

import java.util.HashSet;

/**
 *
 * @author vandit
 */
public class RecycleNumbers {

    private HashSet<String> numbers = new HashSet<String>();
    private HashSet<String> initialTempNumbers = new HashSet<String>();
    private HashSet<String> finalTempNumbers = new HashSet<String>();

    HashSet<Pair> numberPairs = new HashSet<Pair>();


    private void findRecycledNumbers(int start, int end, int places) {


        for (int i = start; i <= end; i++) {
            String initialNumber = Integer.toString(i);
            //if (!(numbers.contains(initialNumber) || finalTempNumbers.contains(initialNumber))) {

                StringBuffer tempNumber = new StringBuffer(initialNumber);
                int len = tempNumber.length();
                int startIndexToMove = len - places;
                String tempString = tempNumber.substring(startIndexToMove);
                if ((places == 1 && tempString.equals("0")) || tempString.charAt(0) == '0') {
                    continue;
                }
                tempNumber.delete(startIndexToMove, len);
                String finalTempNumber = tempString + tempNumber.toString();

                if (! (finalTempNumber.equals(initialNumber) || Integer.parseInt(finalTempNumber) > end || Integer.parseInt(finalTempNumber) < Integer.parseInt(initialNumber))) {
                    numbers.add(initialNumber);
                    finalTempNumbers.add(finalTempNumber);
                    Pair pair = new Pair(finalTempNumber,initialNumber);
                    numberPairs.add(pair);
                }
            }

        

    }

    public HashSet<Pair> findAllRecycledNumbers(int start, int end) {
        int length = Integer.toString(start).length();
        for (int i = 1; i < length; i++) {
            findRecycledNumbers(start, end, i);
        }
        return numberPairs;
    }
}

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class ProblemC {
	public static void main(String[] args) throws IOException {
		new ProblemC();
	}

	private int numOfTest;
	private static final int ATTEMPT_NO = 0;
	private static int SOLVE_HARD = 0;
	int A, B;
	int ans;

	public ProblemC() throws IOException {
		// Scanner input = new Scanner(new File("input.txt"));
		Scanner input = new Scanner(new File("C-small-attempt" + ATTEMPT_NO + ".in"));
		Writer output = new FileWriter("C-small-attempt" + ATTEMPT_NO + ".out");
		if (SOLVE_HARD != 0) {
			input = new Scanner(new File("C-large.in"));
			output = new FileWriter("C-large.in");
		}
		//output = new BufferedWriter(new OutputStreamWriter(System.out));

		numOfTest = input.nextInt();
		for (int test = 1; test <= numOfTest; test++) {
			// read from input
			A = input.nextInt();
			B = input.nextInt();

			process();
			output.write("Case #" + test + ": " + ans + "\n");
		}

		input.close();
		output.flush();
		output.close();
	}

	private void process() {
		ans = 0;
		for (int num = A; num < B; num++) {
			int left = num;
			int right = 0;
			int mul10 = 1;
			Set<Integer> checked = new HashSet<Integer>();
			boolean lastGood = false;
			while (left > 0) {
				if (lastGood) {
					int m = Integer.parseInt(String.valueOf(right) + String.valueOf(left));
					if (m > num && m <= B && !checked.contains(m)) {
						//System.err.println(num + " " + m + " " + ans);
						checked.add(m);
						ans++;
					}
				}
				int lastDigit = left % 10;
				right = lastDigit * mul10 + right;
				left /= 10;
				mul10 *= 10;
				lastGood = (lastDigit != 0);
			}
		}
	}
}