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

package com.forthgo.google.g2012r0;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Created by Xan Gregg.
 * Date: 4/14/12
 */
public class ProblemC {
    public static void main(String[] args) {
        try {
            Scanner in = new Scanner(new File("C.in"));
            PrintWriter out = new PrintWriter(new FileWriter("C.out"));
            //PrintWriter out = new PrintWriter(System.out);
            int t = in.nextInt();
            for (int i = 0; i < t; i++) {
                int a = in.nextInt();
                int b = in.nextInt();
                int k = solve(a, b);
                out.printf("Case #%d: %d%n", i + 1, k);
                out.flush();
            }

        } catch (IOException e) {
            throw new RuntimeException();
        }

    }

    private static int solve(int a, int b) {
        int k = 0;
        int nda = (int) (Math.log10(a) + 1);
        int ndb = (int) (Math.log10(b) + 1);
        Set<Long> pairs = new HashSet<Long>(b - a);
        for (int i = Math.max(2, nda); i <= ndb; i++) {
            k += solve(pairs, a, b, i);
        }
        return k;
    }

    private static int solve(Set<Long> pairs, int a, int b, int nd) {
        int k = 0;
        for (int i = 1; i <= nd / 2; i++)
            k += solve(pairs, a, b, nd, i);
        return k;
    }

    private static int solve(Set<Long> pairs, int a, int b, int nd, int ndc) {
        int c10 = (int) Math.pow(10, ndc);

        int ndd = nd - ndc;
        int d10 = (int) Math.pow(10, ndd);

        int c0 = a / d10;
        int d0 = a / c10;

        int k = 0;
        for (int c = c0; c < c10; c++) {
            if (c * d10 > b)
                break;
            int d00 = d0;
            if (ndc == ndd)
                d00 = Math.max(d00, c + 1);
            for (int d = d00; d < d10; d++) {
                if (d * c10 > b)
                    break;
                int x = c * d10 + d;
                int y = d * c10 + c;
                if (x != y && x >= a && x <= b && y >= a && y <= b) {
                    long xx = Math.min(x, y);
                    long yy = Math.max(x, y);
                    long pair = xx * c10 * d10 + yy;
                    if (!pairs.contains(pair)) {
                        k++;
                        pairs.add(pair);
//                        System.out.printf("%d %d%n", Math.min(x, y), Math.max(x, y));
                    }
                }
            }
        }
        return k;
    }

}
