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

package recycled;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.TreeSet;

/**
 *
 * @author Alfred
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    try {
            FileInputStream fstream = new FileInputStream("C-small-attempt0.in");
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            FileWriter outFile = new FileWriter("out.txt");
            PrintWriter out = new PrintWriter(outFile);
            String line;
            line = br.readLine();
            int cases = Integer.parseInt(line);
            for (int i=1; i<=cases;i++){
                line = br.readLine();
                String[] values = line.split(" ");
                int A = Integer.parseInt(values[0]);
                int B = Integer.parseInt(values[1]);
                int total=0;
                for (int n=A; n<=B;n++){
                    TreeSet<String> solutions = new TreeSet<String>();
                    for (int k=1;k<values[1].length();k++){
                        String m = circshift(n,k);
                        int mVal = Integer.parseInt(m);
                        if(mVal<=B && mVal!=n  && mVal> n && !m.startsWith("0") && m.length()==Integer.toString(n).length() )
                        {
                            solutions.add(m);
                        }                   
                    }
                    total+=solutions.size();
                }
                out.println("Case #"+i+": "+total);
            }
            in.close();
            out.close();
        } catch (Exception e) {//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }

}

    private static String circshift(int n, int k) {
        String nString=Integer.toString(n);
        int len=nString.length();
        String m =  nString.substring(len-k)+nString.subSequence(0, len-k);
        //System.out.println(n+" "+m);
        return m;
    }

}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

public class ProblemC {
	
	public static void main(String [] args)
	{
		new ProblemC();
	}
	
	public ProblemC()
	{
		try
		{
			String [] inputFiles = { "C-small" };//,"A-large" };
			BufferedReader in;
			PrintWriter out;
			for(int i = 0 ; i < inputFiles.length; i++)
			{
				in = new BufferedReader(new FileReader(inputFiles[i]));
				out = new PrintWriter(new FileWriter(inputFiles[i]+".out"),true);
				
				int numCases = Integer.parseInt(in.readLine());
				int min, max;
				String [] items = null;
				for(int j = 0 ; j < numCases; j++)
				{
					items = in.readLine().split("\\s+");
					min = Integer.parseInt(items[0]);
					max = Integer.parseInt(items[1]);
					int total = 0;
					for(int x = min; x <= max; x++)
					{
						for(int y=x+1; y<= max; y++)
						{
							if(checkReycled(x,y))
								total++;
							
						}
					}
					out.println("Case #" + (j+1) + ": " + total);
				}
				in.close();
				out.close();
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	private boolean checkReycled(int x, int y) {
		if(x == y)
			return false;
		else if(x<10 || y<10)
			return false;
		else if(x>=1000)
			return false;
		
		String xstr = new String("" +x);
		String ystr = new String("" +y);
		if(xstr.length() != ystr.length())
			return false;
		
		if(xstr.length() == 2)
		{
			if(xstr.charAt(0) == ystr.charAt(1) &&
					xstr.charAt(1) == ystr.charAt(0))
				return true;
		}
		else
		{
			if(xstr.charAt(0) == ystr.charAt(1) &&
					xstr.charAt(1) == ystr.charAt(2) &&
					xstr.charAt(2) == ystr.charAt(0))
				return true;
			else if(xstr.charAt(0) == ystr.charAt(2) &&
					xstr.charAt(1) == ystr.charAt(0) &&
					xstr.charAt(2) == ystr.charAt(1))
				return true;
		}
		return false;
	}
}
