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.FileOutputStream;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;


public class RecycledNumbers {
	
	public static long shift(long a, byte n){
		return ((a % (long)Math.pow(10, n-1)) * 10 + (a / (long)Math.pow(10, n-1)));
	}
	
	public static byte numberOfDigits(long a){
		byte n = 0;
		while (a > 0){
			n++;
			a /= 10;
		}
		return n;
	}
	
	public static void main(String[] args){
		File in = new File(args[0]);
		File out = new File("b.out");
		FileOutputStream w = null;
		Scanner s = null;
		try{
			w = new FileOutputStream(out);
			s = new Scanner(in);
		} catch (FileNotFoundException e) {}
		int n = s.nextInt();
		for (int i = 1; i <= n; i++){
			long a = s.nextLong();
			long b = s.nextLong();
			byte an = numberOfDigits(a);
			long count = 0;
			
			for(long j = a; j<=b; j++){
				List<Long> l = new LinkedList<Long>();
				long num = j;
				for (byte k = 1; k < an; k++){
					num = shift(num, an);
					if ((num > j) && (num <= b) && !l.contains(num)){
						//System.out.println(j+", "+num);
						l.add(num);
						count++;
					}
				}
			}
			try {
				w.write(("Case #"+ i +": "+count+"\r\n").getBytes());
			} catch (IOException e) {
			}
		}
		try {
			w.close();
			s.close();
		} catch (IOException e) {}
	}

}
