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();
	}

}

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

/**
 * @author Ivan Romanov
 */
public class C {

    private String solve() throws IOException {
        int a = nextInt();
        int b = nextInt();
        int ans = 0;
        for (int i = a; i < b; i++) {
            if (recycle.containsKey(i)) {
                for (int j : recycle.get(i)) {
                    if (j <= b) {
                        ans++;
                        // System.out.println(i + " " + j);
                    }
                }
            }
        }
        return "" + ans;
    }

    private Map<Integer, Set<Integer>> recycle = new HashMap<Integer, Set<Integer>>();

    private void prepare() {
        int mul = 1;
        int dig = 1;
        for (int x = 10; x <= 2000000; x++) {
            if (mul * 10 == x) {
                mul *= 10;
                dig++;
            }
            Set<Integer> recs = new HashSet<Integer>();
            int t = x;
            for (int i = 1; i < dig; i++) {
                int last = t % 10;
                t /= 10;
                t += last * mul;
                if (t > x) {
                    recs.add(t);
                }
            }
            if (!recs.isEmpty()) {
                recycle.put(x, recs);
            }
        }
    }

    private BufferedReader reader;

    private StringTokenizer tt = new StringTokenizer("");

    private String nextToken() throws IOException {
        while (!tt.hasMoreTokens()) {
            tt = new StringTokenizer(reader.readLine());
        }
        return tt.nextToken();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private void run() throws IOException {
        String problem = "C-large";
        reader = new BufferedReader(new FileReader(problem + ".in"));
        PrintWriter writer = new PrintWriter(new File(problem + ".out"));
        try {
            prepare();
            int cases = nextInt();
            int tc = 1;
            while (tc <= cases) {
                writer.print("Case #" + tc + ": ");
                writer.println(solve());
                tc++;
            }
        } finally {
            reader.close();
            writer.close();
        }
    }

    public static void main(String[] args) {
        try {
            new C().run();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}