package codejam;

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

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}


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


public class Recycling {
    
    public static void main(String[] args) throws FileNotFoundException, IOException
    {
        FileInputStream file = new FileInputStream("C:\\Users\\Taghi\\Downloads\\C-small-attempt1.in");
        DataInputStream in2 = new DataInputStream(file);
        Scanner in=new Scanner(new InputStreamReader(in2));
        int numberOfTests=in.nextInt();
        int[] results=new int[numberOfTests];
        for (int i=0;i<numberOfTests;i++)
        {
            int lowerBound=in.nextInt();
            int higherBound=in.nextInt();
            //System.out.println(lowerBound+" "+higherBound);
            int possibilities=0;
            for (int k=lowerBound;k<=higherBound;k++)
            {
                for (int j=k+1;j<=higherBound;j++)
                {
                    String clone=Integer.toString(j);
                    for (int l=0;l<clone.length();l++)
                    {
                        String newClone=clone.substring(clone.length()-l-1,clone.length())+clone.substring(0,clone.length()-l-1);
                        int check=Integer.parseInt(newClone);
                        if (check==k)
                        {
                            possibilities++;
                        }
                    }
                }
            }
            //System.out.println(possibilities);
            results[i]=possibilities;
        }
        for (int i=0;i<numberOfTests;i++)
        System.out.println("Case #"+(i+1)+": "+results[i]);
    }
}
