package codejam;

import java.util.*;
import java.io.*;

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ProblemSample implements Problem {

    private int solution;

    private int A;

    @Override
    public void solve() {

        int resultat = 0;

        for (int n = A; n <= B; n++) {

            // on trouve toutes les rotations de n
            String stringN = Integer.toString(n);
            int size = stringN.length();

            Set<Integer> mySet = new HashSet<Integer>();

            for (int i = 0; i < size; i++) {
                String actuel = rotation(stringN, size, i);
                // le set contient les candidats mais pas les doublons
                mySet.add(Integer.parseInt(actuel));
            }

            // on vÃ©rifie si les rotations trouvÃ©es sont bonnes ou pas.
            for (Integer candidat : mySet) {
                if (candidat > n && candidat <= B) {
                    // si la solution est bonne alors on incrÃ©mente.
                    resultat++;
                }
            }
        }
        this.setSolution(resultat);
    }

    private String rotation(String stringN, int size, int nbRotation) {
        String res = stringN;
        return res.substring(size - nbRotation, size) + res.substring(0, size - nbRotation);
    }

    @Override
    public Object getSolution() {
        return solution;
    }

    public void setSolution(int solution) {
        this.solution = solution;
    }

    public int getA() {
        return A;
    }

    public void setA(int a) {
        A = a;
    }

    public int getB() {
        return B;
    }

    public void setB(int b) {
        B = b;
    }

    public List<Integer> getSums() {
        return sums;
    }

    public void setSums(List<Integer> sums) {
        this.sums = sums;
    }

    private int B;

    private List<Integer> sums = new ArrayList<Integer>();

}