package fixjava;

public class StringUtils {

	/** Repeat the given string the requested number of times. */
	public static String repeat(String str, int numTimes) {
		StringBuilder buf = new StringBuilder(Math.max(0, str.length() * numTimes));
		for (int i = 0; i < numTimes; i++)
			buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the left hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padLeft(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(padChar);
		for (int i = 1, mi = bufSize - str.length(); i < mi; i++)
			buf.append(padChar);
		buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the right hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padRight(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(str);
		buf.append(padChar);
		while (buf.length() < bufSize)
			buf.append(padChar);
		return buf.toString();
	}

	/** Intern all strings in an array, skipping null elements. */
	public static String[] intern(String[] arr) {
		for (int i = 0; i < arr.length; i++)
			arr[i] = arr[i].intern();
		return arr;
	}

	/** Intern a string, ignoring null */
	public static String intern(String str) {
		return str == null ? null : str.intern();
	}

}

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

import java.util.Scanner;


public class RecycledNumbersLarge2 {

    public void solve() {

        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt(), t = 0;
        int count = 0, recy = 0;
        while (t < T) {
            int A = sc.nextInt();
            int B = sc.nextInt();

            int n = A, m = 0;//A â¤ n < m â¤ B

            while (n < B) {
                String nn = String.valueOf(n);
                int digits = nn.length();
                int check[] = new int[digits - 1];
                int j = 1;

                while (j < digits) {
                    String mm = nn.substring(digits - j, digits) + nn.substring(0, digits - j);
                    m = Integer.parseInt(mm);

                    if (m <= B && m > n) {

                        int k = 0;
                        while (k < check.length) {
                            if (check[k] == m) {
                                break;
                            } else if (check[k] == 0) {
                                check[k] = m;
                                break;
                            }


                            ++k;
                        }
                    }
                    ++j;
                }
                count = 0;
                for (int i = 0; i < check.length; ++i) {
                    if (check[i] != 0) {
                        count++;
                    }
                }

                recy += count;


                ++n;

            }
            System.out.println("Case #" + (t + 1) + ": " + recy);
            recy = 0;


            ++t;
        }


    }

    public static void main(String[] args) {

        new RecycledNumbersLarge2().solve();
        /*
         * int n = 12345; int j = 2; String nn = String.valueOf(n); int digits =
         * nn.length(); String mm = nn.substring(digits - j, digits) +
         * nn.substring(0, digits - j);
        System.out.println(mm);
         */
    }
}
