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

import java.io.*;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class RecycledNumbers {


    public static final String LINE_SEPARATOR = System.getProperty("line.separator");

    public static int recycleNum(int a, int b) {
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        int n = String.valueOf(a).length();
        int c = 0;
        for (int i = a; i <= b; i++) {
            for (int j = 1; j < n ; j++) {
                int rNum = rotateRight(i, j);
                if (i < rNum && rNum <= b) {
                    if (!map.containsKey(rNum) || map.get(rNum) != i) {
                        map.put(rNum, i);
                        c++;
                    }
                }
            }
        }
        return c;
    }

    private static int rotateRight(int i, int j) {
        int length = String.valueOf(i).length();
        int sP = (int) Math.pow(10, j);
        int bP = (int) Math.pow(10, length - j);
        int rem = i % sP;
        return ((i - rem) / sP) + (rem * bP);
    }

    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(new File("D:\\codejam\\C-small-attempt0.in"));
        Writer writer = new OutputStreamWriter(new FileOutputStream("D:\\codejam\\C-small-attempt.out"));
        Integer n = Integer.valueOf(scanner.nextLine());
        for (int i = 1; i <= n; i++) {
            System.out.println();
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            writer.write("Case #" + i + ": " + recycleNum(a, b));
            writer.write(LINE_SEPARATOR);
        }
        scanner.close();
        writer.close();
    }

}
