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 gcj2012.qr;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/**
 *
 * @author Scott DellaTorre
 */
public class C {

    public static void main(String[] args) throws IOException {

        BufferedReader in = new BufferedReader(new FileReader("src/gcj2012/qr/in"));
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("src/gcj2012/qr/C.out")));

        int T = Integer.parseInt(in.readLine());
        for (int i = 0; i < T; i++) {
            StringTokenizer st = new StringTokenizer(in.readLine());
            int A = Integer.parseInt(st.nextToken()); // Number of Googlers
            int B = Integer.parseInt(st.nextToken()); // Number of suprising cases

            int pairs = 0;

            for (int j = A; j <= B; j++) {
                pairs += countRecycled(j, B);
            }

            out.println("Case #" + (i + 1) + ": " + pairs);
        }

        out.close();
    }

    private static int countRecycled(int number, int max) {
        List<Integer> list = new ArrayList<>();
        int log10 = (int) Math.log10(number);
        for (int i = 1; i <= log10; i++) {
            int recycled = recycle(number, i, max);
            if (recycled != -1 && !list.contains(recycled)) {
                list.add(recycled);
            }
        }
        return list.size();
    }

    private static int recycle(int number, int count, int max) {
        int oldNumber = number;

        int divisor = (int) Math.pow(10, count);
        int end = number % divisor;
        number /= divisor;
        int multiplicand = (int) Math.pow(10, (int) Math.log10(number) + 1);
        number += end * multiplicand;

        if (number <= oldNumber || number > max) {
            return -1;
        }
        return number;
    }
}
