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

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: james
 * Date: 4/14/12
 * Time: 3:20 PM
 * To change this template use File | Settings | File Templates.
 */
public class Recycled
{
    public static void main(String[] args) throws FileNotFoundException
    {
        Scanner sc = new Scanner(new File("inputs/recycled.in"));
        
        int cases = sc.nextInt();
        
        for (int i = 1; i <= cases; i++)
        {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int num = 0;
            
            for (int j = a; j <= b; j++)
            {
                String s = j + "";
                HashSet<Integer> set = new HashSet<Integer>();

                for (int k = 1; k < s.length(); k++)
                {
                    String rotated = rotate(s, k);
                    if (!rotated.startsWith("0"))
                    {
                        int paired = Integer.parseInt(rotated);

                        if (paired > j && paired <= b)
                        {
                            set.add(paired);
                        }
                    }
                }

                num += set.size();
            }
            
            System.out.printf("Case #%s: %s\n", i, num);
        }
    }
    
    private static String rotate(String s, int i)
    {
        String rotated = s.substring(s.length() - i) + s.substring(0, s.length() - i);

        return rotated;
    }
}
