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

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gcj2012.qual;

import java.io.File;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author scbit
 */
public class P3 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        new P3().run();
    }
    PrintWriter pw;

    void run() throws Exception {
        File infile = new File("C-large.in");
        String outfile = "result";
        pw = new PrintWriter(outfile);
        int N = 0;
        //BufferedReader br=new BufferedReader(new FileReader(infile));
        //N=Integer.parseInt(br.readLine());
        Scanner sc = new Scanner(infile);
        N = sc.nextInt();

        for (int case_i = 1; case_i <= N; case_i++) {
            int result = 0;
            int A=sc.nextInt();
            int B=sc.nextInt();
            for(int n=A;n<=B;n++){
                int d=calcnum(n);
                int m=n;
                for(int i=1;i<d;i++){
                    int gewei=m%10;
                    m=m/10;
                   
                    if(gewei==0) continue;
                    for(int ii=1;ii<d;ii++){
                        gewei=gewei*10;
                    }
                    m=m+gewei;
                    if(m==n) break;
                    if(m>n && m <=B) result++;
                }
            }
            
            
            
            pw.printf("Case #%d: %s\n", case_i, result);
            System.out.printf("Case #%d: %s\n", case_i, result);
        }
        pw.close();
    }
    int calcnum(int num){
        int t=num;
        int c=0;
        
        while(t>0){
            t=t/10;
            c++;
        }
        return c;
        
    }
}
