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

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}

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

public class RecycledNumbers {
    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner(String fileName) throws IOException {
            br = new BufferedReader(new FileReader(new File(fileName)));
        }

        public String nextToken() throws IOException, NullPointerException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public String nextString() throws IOException, NullPointerException {
            st = null;
            return br.readLine();
        }

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

        void close() throws IOException {
            br.close();
        }
    }

    public static void main(String[] args) throws IOException {
        final String name = "C-large";
        MyScanner in = new MyScanner(name + ".in");
        PrintWriter out = new PrintWriter(name + ".txt");

        int t = in.nextInt();
        for (int i = 1; i <= t; i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            int res = 0;
            for (int n = a; n < b; n++) {
                int m = n;
                int l = 0;
                int k = 1;
                while (m != 0) {
                    m /= 10;
                    l++;
                    k *= 10;
                }
                m = n;
                k /= 10;
                int[] w = new int[l];
                for (int j = 1; j < l; j++) {
                    m = (m % 10) * k + m / 10;
                    w[j] = m;
                    boolean f = true;
                    for (int q = 1; q < j; q++) {
                        if (m == w[q]) {
                            f = false;
                            continue;
                        }
                    }
                    if (m > n && a <= m && m <= b && f) {
                        res++;
                    }
                }
            }
            out.println("Case #" + i + ": " + res);
        }

        in.close();
        out.close();
    }
}

