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.util.*;
import java.io.*;

public class CodeJam {
    public static void main(String[] args) {
        try {
            //recycleLarge(1000000, 2000000);
            // read
            FileInputStream instream = new FileInputStream("A-small.in");
            DataInputStream in = new DataInputStream(instream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));

            // write
            FileOutputStream outstream = new FileOutputStream("A-small.out");
            DataOutputStream out = new DataOutputStream(outstream);
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));

            // reading file information
            int testcases = Integer.parseInt(br.readLine());
            for (int i = 0; i < testcases; i++) {
                // -------------------------------------------------------------------------------------------------------------
                String line = br.readLine();
                String[] items = line.split(" ");
                int A = Integer.parseInt(items[0]);
                int B = Integer.parseInt(items[1]);
                // -------------------------------------------------------------------------------------------------------------
                bw.write("Case #" + (i + 1) + ": " + recycleLarge(A, B) + "\r\n");
            }

            // close input file
            in.close();
            // close output file
            bw.flush();
            out.close();
        } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
        }
    }

    private static int eval(int i) {
        if (i < 0)
            return 0;
        else
            return i;
    }

    private static void printArray(Object[] array) {
        for (Object ch : array)
            System.out.print(ch);
    }

    private static boolean isRecycled(String str, String m) {
        for (int i = 1; i < str.length(); i++) {
            String digits = str.substring(i) + str.substring(0, i);
            if (digits.equals(m)) return true;
        }
        return false;
    }

    private static String convertTo(int n) {
        String str = "";
        while (n != 0) {
            str = (n % 10) + str;
            n = n / 10;
        }
        return str;
    }

    private static long recycle(int A, int B) {
        long count = 0;
        for (int n = A; n < B; n++) {
            for (int m = n + 1; m <= B; m++) {
                String nstr = convertTo(n);
                String mstr = convertTo(m);
                if (isRecycled(nstr, mstr))
                    count++;
            }
        }
        return count;
    }

    private static long evaluate(int n, int A, int B) {
        String nstr = convertTo(n);
        int c = 0;
        for (int i = 1; i < nstr.length(); i++) {
            String digits = nstr.substring(i) + nstr.substring(0, i);
            int variation = Integer.parseInt(digits);
            if(digits.charAt(0) == '0') continue;
            if (digits.equals(nstr)) continue;
            if (variation <= B && variation >= A){
                visit[variation] = true;
                c++;
            }

        }
        return sum(c);
    }

    private static long sum(int n){
        return n * (n+1) / 2;
    }

    private static long recycleLarge(int A, int B) {
        long sum = 0;
        visit = new boolean[B+1];
        for(int i=0; i<B; i++) visit[i] = false;
        for (int n = A; n <= B; n++) {
            if (visit[n] == false)
                sum += evaluate(n, A, B);
        }
        return sum;
    }

    private static boolean[] visit = null;


}

