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.LinkedList;
import java.util.Scanner;


public class Recycled {
	public static void main(String[] args) throws IOException {
		Scanner s = new Scanner(new File("io/recycled-biga.in"));
		FileWriter fw = new FileWriter(new File("io/recycled.out"));
		
		int cases = s.nextInt();
		s.nextLine();
		for(int i = 0; i < cases; i++) {
			int a = s.nextInt();
			int b = s.nextInt();
			String out = "Case #" + (i+1) + ": " + solve(a, b);
			System.out.println(out);
			fw.write(out + "\n");
		}
		
		s.close();
		fw.close();
	}

	private static int solve(int n, int m) {
		int rotations = Integer.toString(n).length();
		int count = 0;
		
		String nStr;
		
		
		// For each n to m
		for(int i = n; i < m; i++) {
			LinkedList<Integer> l = new LinkedList<Integer>();
			nStr = "" + i;
			// Rotate through all possible configurations of n
			for(int r = 0; r < rotations -1; r++) {
				nStr = nStr.substring(rotations - 1) + nStr.substring(0, rotations-1);
				if(nStr.charAt(0) != '0') {
					int newN = Integer.parseInt(nStr);
					if(newN > i && newN <= m) {
						if(l.contains(newN) == false) {
							l.add(newN);
							count++;
						}
					}
				}
			}
		}
		
		return count;
	}

}
