import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		int casos=1, a, b, n, m, cont;
		while(t!=0){
			a=sc.nextInt();
			b=sc.nextInt();
			if(a>b){
				int aux=a;
				a=b;
				b=aux;
			}
			System.out.printf("Case #%d: ",casos++);
			if(a==b){
				System.out.printf("%d\n",0);
			}else{
				cont=0;
				for(n=a;n<b;n++){					
					for(m=n+1;m<=b;m++){					
						if(isRecycled(n,m)) cont++;
					}
				}
				System.out.printf("%d\n",cont);
			}
			t--;
		}		
	}
	public static boolean isRecycled(int n1, int n2){
		String s1, s2, aux;
		s1 =  String.valueOf( n1 );
		s2 =  String.valueOf( n2 );		
		boolean r = false;		
		for(int i=0;i<s1.length();i++){
			aux="";
			aux=s1.substring(i,s1.length())+s1.substring(0,i);
//			System.out.println(aux);
			if(aux.equals(s2)){
				r=true;
				break;
			}
		}		
		return r;
	}
}


import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Vector;

public class C {

	/**
	 * @param args
	 * @throws FileNotFoundException
	 */
	public static void main(String[] args) throws FileNotFoundException
	{
		Scanner scan = new Scanner(new File("C-small-attempt0.in"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		int cases = scan.nextInt();
		for (int r = 1; r <= cases; r++)
		{
			int a = scan.nextInt();
			int b = scan.nextInt();

			Vector<Integer>[] v = new Vector[b + 1];
			for (int i = 0; i < v.length; i++)
				v[i] = new Vector<Integer>();

			long ret = 0;
			for (int n = a; n <= b; n++)
			{
				String sn = n + "";
				for (int j = sn.length()-1; j > 0; j--)
				{
					String sm = sn.substring(j) + sn.substring(0, j);
					int m = Integer.parseInt(sm);
					sm = m + "";
					if (sm.length() == sn.length() && m <= b && m > n)
					{
						if (!v[n].contains(m))
						{
							v[n].add(m);
							v[m].add(n);
							ret++;
						}
					}
				}
			}
			out.println("Case #" + r + ": " + ret);
		}

		out.close();
		scan.close();
	}

}
