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


public class C {
	
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(new File("C-small.in"));
		FileWriter fw = new FileWriter("C-small.out");
		
		int T = in.nextInt();
		
		for (int tc = 1; tc <= T; tc++) {
			int A = in.nextInt();
			int B = in.nextInt();
			int count = 0;
			for(int i = A; i < B; i++) {
				for(int j = i + 1; j <= B; j++) {
					if(isRecycledPair(i, j)) {
						count ++;
					}
				}
			}
			fw.write ("Case #" + tc + ": " + count + "\n");
		}
		fw.flush();
		fw.close();
	}
	
	public static boolean isRecycledPair(int a, int b) {
		boolean isRecycled = false;
		String str1 = Integer.toString(a);
		String str2 = Integer.toString(b);
		int len = str1.length();
		for(int i = 0; i < len - 1; i++ ) {
			str1 = str1.substring(len - 1) + str1.substring(0, len - 1);
			if(str1.equals(str2))
				isRecycled = true;
		}
		return isRecycled;
	}

}
