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

public class C {

    void solve() throws IOException {
        in("C-large.in"); out("C-large.out");

        long tm = System.currentTimeMillis();
        boolean[] mask = new boolean[2000000];
        int[] r = new int[10];
        int t = readInt();
        for (int cs = 1; cs <= t; ++cs) {
            int a = readInt();
            int b = readInt();
            int ans = 0;
            for (int m = a + 1; m <= b; ++m) {
                char[] d = String.valueOf(m).toCharArray();
                int c = 0;
                for (int i = 1; i < d.length; ++i) {
                    if (d[i] != '0' && d[i] <= d[0]) {
                        int n = 0;
                        for (int j = 0; j < d.length; ++j) {
                            int jj = i + j;
                            if (jj >= d.length) jj -= d.length;
                            n = n * 10 + (d[jj] - '0');
                        }
                        if (n >= a && n < m && !mask[n]) {
                            ++ans;
                            mask[n] = true;
                            r[c++] = n;
                        }
                    }
                }
                for (int i = 0; i < c; ++i) {
                    mask[r[i]] = false;
                }
            }
            println("Case #" + cs + ": " + ans);
            //System.out.println(cs);
        }
        System.out.println("time: " + (System.currentTimeMillis() - tm));
        exit();
    }

    void in(String name) throws IOException {
        if (name.equals("__std")) {
            in = new BufferedReader(new InputStreamReader(System.in));
        } else {
            in = new BufferedReader(new FileReader(name));
        }
    }

    void out(String name) throws IOException {
        if (name.equals("__std")) {
            out = new PrintWriter(System.out);
        } else {
            out = new PrintWriter(name);
        }
    }

    void exit() {
        out.close();
        System.exit(0);
    }

    int readInt() throws IOException {
        return Integer.parseInt(readToken());
    }

    long readLong() throws IOException {
        return Long.parseLong(readToken());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readToken());
    }

    String readLine() throws IOException {
        st = null;
        return in.readLine();
    }

    String readToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    boolean eof() throws IOException {
        return !in.ready();
    }

    void print(String format, Object ... args) {
        out.println(new Formatter(Locale.US).format(format, args));
    }

    void println(String format, Object ... args) {
        out.println(new Formatter(Locale.US).format(format, args));
    }

    void print(Object value) {
        out.print(value);
    }

    void println(Object value) {
        out.println(value);
    }

    void println() {
        out.println();
    }

    StringTokenizer st;

    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        new C().solve();
    }
}


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author JY
 */
public class ProblemC{

    private static int testNum;
    private static int[][] data;

    public static void main(String[] args) {
        input();
        int[] result = calc();
        output(testNum, result);
    }

    private static void input() {
        Scanner in = null;
        in = new Scanner(System.in);
        testNum = Integer.parseInt(in.nextLine());
        data = new int[testNum][];
        for (int i = 0; i < testNum; i++) {
            String line = in.nextLine();
            String[] nums = line.split(" ");
            data[i] = new int[2];
            data[i][0] = Integer.parseInt(nums[0]);
            data[i][1] = Integer.parseInt(nums[1]);
        }
    }

    private static int[] calc() {
        HashSet<Integer> hs = new HashSet<Integer>();
        int[] res = new int[testNum];
        for (int i = 0; i < testNum; i++) {
            int result = 0;
            int a = data[i][0];
            int b = data[i][1];
            int length = getLength(b);
            for (int number = a; number <= b; number++) {
                hs.clear();
                for (int shifts = 1; shifts < length; shifts++) {
                    int shiftnum = shift(number, shifts);
                    if (shiftnum <= b && shiftnum > number && !hs.contains(shiftnum)) {
                        result++;
                        hs.add(shiftnum);
                    }
                }
            }
            res[i] = result;
        }
        return res;
    }

    private static int getLength(int n) {
        return String.valueOf(n).length();
    }

    private static int shift(int num, int shift) {
        String numS = String.valueOf(num);
        int len = numS.length();
        numS = reverse(numS, 0, len - shift - 1);
        numS = reverse(numS, len - shift, len - 1);
        numS = reverse(numS, 0, len - 1);
        return Integer.parseInt(numS);
    }

    private static String reverse(String target, int start, int end) {
        char[] tar = target.toCharArray();
        while (start < end) {
            char tmp = tar[start];
            tar[start] = tar[end];
            tar[end] = tmp;
            start++;
            end--;
        }
        return new String(tar);
    }

    private static void output(int testNum, int[] res) {
        for (int i = 0; i < testNum; i++) {
            System.out.printf("Case #%d: %s\n", i + 1, res[i]);
        }
    }
}
