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

public class C {
    static int[] ten;

    static {
        ten = new int[10];
        ten[0] = 1;
        for (int i = 1; i < ten.length; ++i) {
            ten[i] = ten[i - 1] * 10;
        }
    }

    static int max(int x) {
        int n = 0;
        while (ten[n + 1] <= x) {
            ++n;
        }
        int y = x;
        for (int i = 0; i < n; ++i) {
            x = x / 10 + x % 10 * ten[n];
            y = Math.max(x, y);
        }
        return y;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int re = in.nextInt();
        int[] c = new int[10000000];
        for (int ri = 1; ri <= re; ++ri) {
            int a = in.nextInt();
            int b = in.nextInt();
            Arrays.fill(c, 0);
            for (int i = a; i <= b; ++i) {
                ++c[max(i)];
            }
            long s = 0;
            for (int i: c) {
                s += i * (i - 1) / 2;
            }
            System.out.println("Case #" + ri + ": " + s);
        }
    }
}

