package qual;

import java.util.Scanner;

public class RecycledNumbers {

	public static void main(String[] args) {
		new RecycledNumbers().run();

	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int result = solve(A, B);
			System.out.printf("Case #%d: %d\n", t + 1, result);
		}
	}

	public int solve(int A, int B) {
		int result = 0;
		for (int i = A; i <= B; i++) {
			int dig = (int) Math.log10(A/*same as B*/) + 1;
			int aa = i;
			for (int d = 0; d < dig - 1; d++) {
				aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
				if (i == aa) {
					break;
				}
				if (i < aa && aa <= B) {
//					System.out.printf("(%d, %d) ", i, aa);
					result++;
				}
			}
		}
		return result;
	}

}

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


class Pair implements Comparable<Pair>{
    int a , b;

    public Pair(int a, int b) {
        this.a = a;
        this.b = b;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Pair other = (Pair) obj;
        if (this.a != other.a) {
            return false;
        }
        if (this.b != other.b) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = a*3;
        return hash;
    }

    public int compareTo(Pair o) {
        if ( o.a != this.a ){
            return this.a - o.a;
        }else{
            return this.b - o.b;
        }
    }


}

/**
 *
 * @author Saul Hidalgo
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            Scanner sc = new Scanner(new File("test.txt"));
            PrintStream ps = new PrintStream(new File("output.txt"));

            int T = sc.nextInt();
            for ( int t = 1 ; t <= T ; t++ ){
                int n = sc.nextInt() , m = sc.nextInt();
                int ans = 0;
                TreeSet<Pair> tree = new TreeSet<Pair>();

                for ( int i = n ; i <= m ; i++ ){
                    String num = i + "";
                    for ( int j = 1 ; j < num.length() ; j++ ){
                        String conv = num.substring(j) + num.substring(0, j);
                        int tt = Integer.parseInt(conv);
                        Pair p = new Pair(i, tt);
                        if ( tt > i && tt <= m && !tree.contains(p)){
                            ++ans;
                            tree.add(p);
                        }
                    }
                }
                ps.println("Case #" + t + ": " + ans);
            }

        }
        catch (FileNotFoundException ex) {
            // =(
        }
    }
}
