
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;

public class Recycle
{
	public static void main(String[] args)
	{
/*		Set<Integer> perms = getPermutations(123456);
		
		for(Integer i: perms)
			System.out.println(i);*/
	
		try
		{
			Scanner s = new Scanner(new File("recycle.in"));
			BufferedWriter w = new BufferedWriter(new FileWriter(new File("recycle.out")));
			int numCases = s.nextInt();
			s.nextLine();
			
			for(int n = 1;n <= numCases; n++)
			{
				int A = s.nextInt();
				int B = s.nextInt();
				int count = 0;
				for(int k = A; k <= B; k++)
				{
					count += getNumPairs(k, B);
				}
				
				w.write("Case #" + n + ": " + count + "\n");
			}
			
			w.flush();
			w.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public static int getNumPairs(int n, int B)
	{
		Set<Integer> possibles = getPermutations(n);
		int count = 0;
		for(Integer i : possibles)
			if(i > n && i <= B)
				count++;
		return count;
	}
	
	public static Set<Integer> getPermutations(int n)
	{
		Set<Integer> perms = new TreeSet<Integer>();
		char[] digits = String.valueOf(n).toCharArray();
		
		for(int firstPos = 1; firstPos < digits.length; firstPos++)
		{
			String toBuild = "";
			for(int k = 0; k < digits.length; k++)
				toBuild += digits[(firstPos + k) % digits.length];
			perms.add(Integer.parseInt(toBuild));
		}
		return perms;
	}
	

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

import com.sun.org.apache.xpath.internal.FoundIndex;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author karim
 */
public class Question3 {

    static Map<Pair, Integer> found = new HashMap<Pair, Integer>();

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        BufferedWriter out = new BufferedWriter(new FileWriter("output.out"));
        BufferedReader in = new BufferedReader(new FileReader("C-small-attempt0.in"));
        int numOfcases = Integer.parseInt(in.readLine());
        for (int caseNum = 1; caseNum <= numOfcases; caseNum++) {
            found = new HashMap<Pair, Integer>();
            String input = in.readLine();
            Scanner s = new Scanner(input);
            int a = s.nextInt();
            int b = s.nextInt();
            long output = 0;
            if (b >= 10) {
                for (int currentNum = b; currentNum >= a; currentNum--) {
                    int temp = currentNum;
                    int divisor = 10;
                    while (temp / divisor != 0) {
                        int div = temp / divisor;
                        int reminder = temp % divisor;
                        divisor *= 10;
                        int newNumber = Integer.parseInt("" + reminder + div);
                        if (newNumber >= a && newNumber <= b && newNumber != currentNum) {
                            Pair p = new Pair(newNumber, currentNum);
                            if (!found.containsKey(p)) {
                                System.out.println(currentNum + "  " + newNumber);
                                found.put(p, 1);
                                output++;
                            }
                        }

                    }

                }
            }
            out.write("Case #" + caseNum + ": " + output);
            out.newLine();
        }
        out.flush();
        out.close();
        in.close();
    }
}
