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;
	}
}

package recycling;

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

public class Main {
	
	public static int lint(int n){
		if(n == 0)
			return 0;
		return 1 + lint(n / 10);
	}
	
	public static void permut(int[] tab){
		int l = tab.length;
		int temp = tab[l - 1];
		for(int i = l - 1; i > 0; i--){
			tab[i] = tab[i - 1];
		}
		tab[0] = temp;
	}
	
	public static int toInt(int[] tab){
		int res = 0;
		int m = 1;
		for(int i = tab.length - 1; i >= 0; i--){
			res += m * tab[i];
			m *= 10;
		}
		return res;
	}
	
	public static int[] toTab(int n){
		int[] res = new int[lint(n)];
		int temp = n;
		for(int i = res.length - 1; i >= 0; i--){
			res[i] = temp % 10;
			temp /= 10;
		}
		return res;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//String fileName = args[0];
		String fileName = "recycling/C-small-attempt0.in";
		Scanner sC = null;
		try {
			sC = new Scanner(new File(fileName));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		int T = sC.nextInt();
		int A, B, l;
		
		for(int i = 0; i < T; i++){
			A = sC.nextInt();
			B = sC.nextInt();
			
			l = lint(A);
			
			int[] tab;
			
			int temp;
			
			int count = 0;
			
			for(int j = A; j < B; j++){
				tab = toTab(j);
				for(int k = 0; k < l - 1; k++){
					permut(tab);
					temp = toInt(tab);
					//System.out.println(j + " " + temp);
					if(temp > j && temp <= B){
						count++;
						//System.out.println(j + " " + temp);
					}
				}
			}
			
			System.out.println("Case #" + (i + 1) + ": " + count);
		}

	}

}
