import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
package br.com.feasoft.jam;

import java.io.IOException;
import java.util.*;

/**
 * User: Homer
 * Date: 4/13/12
 * Time: 9:30 PM
 */
public class Recycle {

    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int numberOfCases = scanner.nextInt();

        for (int i = 0; i < numberOfCases; i++) {
            int number1 = scanner.nextInt();
            int number2 = scanner.nextInt();
            int answer = 0;

            Map<Integer, Set<Integer>> pairs = new HashMap<Integer, Set<Integer>>();
            for ( int j = number1; j <= number2; j++) {
                int size = Double.valueOf(Math.log10(j)).intValue();
                for (int k = 1; k <= size; k++) {
                    int number = shift(j, k);
                    if(pairs.get(j) == null) {
                        pairs.put(j, new HashSet<Integer>());
                    }
                    if (number != j && number >= number1 && number <= number2 && !pairs.get(j).contains(number)) {
                        answer++;
                        if(pairs.get(number) == null) {
                            pairs.put(number, new HashSet<Integer>());
                        }
                        pairs.get(j).add(number);
                        pairs.get(number).add(j);
                    }
                }
            }
            System.out.printf("Case #%d: %d\n", i + 1, answer);
        }
    }

    public static int shift(int number, int quantity) {
        int digits = Double.valueOf(Math.log10(number)).intValue()+1;
        int lastDigitsGoingForward = Double.valueOf(number % Math.pow(10, quantity)).intValue();
        int newFirstPart = Double.valueOf(lastDigitsGoingForward * Math.pow(10, digits-quantity)).intValue();
        int firstDigitsGoingBack = Double.valueOf(number / Math.pow(10, quantity)).intValue();
        return newFirstPart + firstDigitsGoingBack;
    }
}
