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.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

class Main
{

    static int p[] =
    {
        1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
    };

    static int length(int n)
    {
        int ans = 0;
        while (n > 0)
        {
            ++ans;
            n /= 10;
        }
        return ans;
    }

    static int rotate(int n, int len)
    {
        int d = n % 10;
        n /= 10;
        n = p[len - 1] * d + n;
        return n;
    }

    static void redirect() throws FileNotFoundException
    {
        System.setIn(new FileInputStream("c.in"));
        System.setOut(new PrintStream("c.out"));
    }

    public static void main(String[] args) throws FileNotFoundException
    {

        redirect();

        Scanner in = new Scanner(System.in);
        int tc;
        tc = in.nextInt();
        for (int t = 1; t <= tc; t++)
        {
            int a, b, n, x, y;
            a = in.nextInt();
            b = in.nextInt();
            Set<Pair> s = new TreeSet<Pair>();

            int ans ;
            int len = length(a);
            for (int i = a; i <= b; i++)
            {
                n = i;
                if (i == p[len])
                    len++;

                while (true)
                {
                    n = rotate(n, len);
                    if (n == i)
                        break;
                    if (a <= n && n <= b)
                    {
                        x = i;
                        y = n;
                        if (x > y)
                        {
                            int tmp = x;
                            x = y;
                            y = tmp;
                        }


                        s.add(new Pair(x, y));
                    }
                }
            }

            ans = s.size();

            System.out.printf("Case #%d: %d\n", t, ans);
        }
    }
}

class Pair implements Comparable<Pair>
{
    int x,y;

    public Pair(int x, int y)
    {
        this.x = x;
        this.y = y;
    }

    @Override
    public int compareTo(Pair p)
    {
        if (x != p.x) return x - p.x;
        else return y - p.y;
    }


}
