import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class CopyOfCopyOfMain {

	static int ndigits(int n) {
		return (int) (Math.log10(n) + 1);
	}

	static int rot(int n, int dig) {
		return (int) ((n % 10) * Math.pow(10, dig - 1)) + (int) (n / 10);
	}

	public static void main(String[] args) throws FileNotFoundException {
		String file = "C-large";
		Scanner in = new Scanner(new File(file + ".in"));
		PrintWriter out = new PrintWriter(new File(file + ".out"));

		int T = in.nextInt();
		for (int t = 1; t <= T; t++) {
			int A = in.nextInt();
			int B = in.nextInt();

			int c = 0;
			int[] list = new int[ndigits(B)];
			numbers: for (int i = A; i <= B; i++) {
				int digs = ndigits(i);
				int rot = i;
				int pairs = 0;

				Arrays.fill(list, -1);
				list[0] = i;

				digits: for (int j = 1; j <= digs + 1; j++) {

					rot = rot(rot, digs);
					if(rot < i)
						continue;

					if (A <= rot && rot <= B) {
						for (int k = 0; k < j; k++) {
							if (list[k] == rot) {
								continue digits;
							}
						}
						pairs++;
						list[j] = rot;
					}
				}

				//c += pairs * (pairs + 1) / 2;
				c += pairs ;
				// c+=digs;
			}
			out.println("Case #" + t + ": " + c);
		}

		in.close();
		out.close();
	}
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ex3;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author Jean-Nicolas
 */
public class Ex3 {

    public static String readFile(File file) {

        String result = "";
        try {
            InputStream ips = new FileInputStream(file);
            InputStreamReader ipsr = new InputStreamReader(ips);
            BufferedReader br = new BufferedReader(ipsr);
            String line;
            while ((line = br.readLine()) != null) {
                result += line + "\n";
            }
            br.close();
            result.substring(0, Math.max(0, result.length() - 1)); // Deletion of the last \n
        } catch (Exception e) {
            System.out.println(e.toString());
        }

        return result;
    }

    public static void writeFile(File file, String data) {
        try {
            BufferedWriter out = new BufferedWriter(new FileWriter(file));
            out.write(data);
            out.close();
        } catch (IOException ex) {
            System.out.println("Exception ");
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here


        String data = readFile(new File("data.txt"));
        String[] lines = data.split("\n");
        String resultStr = "";

        ArrayList<Integer> results = new ArrayList<>();

        for (int i = 1; i < lines.length; i++) {
            String[] values = lines[i].split(" ");

            int A = Integer.parseInt(values[0]);
            int B = Integer.parseInt(values[1]);

            HashMap<Pair, Boolean> alreadyUsed = new HashMap<>();


            for (int n = A; n <= B; n++) {
                String nStr = String.valueOf(n);

                for (int j = 0; j < nStr.length(); j++) {
                    String nStr2 = nStr.substring(j) + nStr.substring(0, j);
                    int m = Integer.parseInt(nStr2);

                    Pair pair = new Pair(n, m);
                    
                    if (alreadyUsed.get(pair) == null && (A <= n && n < m && m <= B)) {
                        alreadyUsed.put(pair, true);
                    }
                }

            }

            resultStr += "Case #" + i + ": " + alreadyUsed.size() + "\n";
        }

        resultStr = resultStr.substring(0, resultStr.length() - 1);
        System.out.println(resultStr);
        writeFile(new File("result.txt"), resultStr);
    }
}
