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

package com.codejam;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class ProblemC {

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

        Scanner sc = new Scanner(new File("C-large.in"));
        int T = sc.nextInt();
        sc.nextLine();

        for (int i = 0; i < T; i++) {
            int A = sc.nextInt();
            int B = sc.nextInt();

            System.out.println("Case #" + (i + 1) + ": " + solve(A, B));
        }

    }

    private static long solve(int a, int b) {

        if (a < 10) {
            return 0L;
        }

        long count = 0L;
        int len = (int) Math.floor((Math.log10((double) a)));

        int factor = 1;
        for (int i = 0; i < len; i++) {
            factor *= 10;
        }

        boolean[] mark = new boolean[b - a + 1];

        for (int n = a; n <= b; n++) {

            if (mark[n - a]) {
                continue;
            }

            int nn = n;

            Set<Integer> pairs = new HashSet<Integer>();
            pairs.add(nn);
            mark[nn - a] = true;
            for (int i = 0; i < len; i++) {
                nn = (nn % 10) * factor + nn / 10;
                if (nn >= a && nn <= b) {
                    pairs.add(nn);
                    mark[nn - a] = true;
                }
            }

            count += cn2(pairs.size());
        }

        return count;
    }

    private static long cn2(int size) {
        long s = (long) size;
        return s * (s - 1) / 2L;
    }

}
