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 codejam2012;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;

/**
 *
 * @author Luis Sergio Curay
 */
public class c {

    public c() {
        Scanner in= new Scanner(System.in);
        int t= in.nextInt();
        for (int i = 0; i < t; i++) {
            int a= in.nextInt();
            int b= in.nextInt();
            HashSet<Integer> nums= new HashSet<Integer>();
            int res= 0;
            for (int j = a; j <= b; j++) {
                HashSet<Integer> comb= combinaroty(j);
                for (Integer num : comb) {
                    if(num >= a && num <= b && num != j) {
                        if(!nums.contains(num)) {
                            nums.add(j);
                            res++;
                        }
                    }
                }
            }
            System.out.println("Case #" + (i + 1) + ": " + res);
        }
    }
    
    public int reverse(int n) {
        String num= String.valueOf(n);
        for (int i = 0; i < num.length() - 1; i++) {
            num= num.substring(num.length() - 1) + num.substring(0, num.length() - 1);
        }
        return Integer.parseInt(num);
    }
    
    private HashSet<Integer> combinaroty(int n) {
        HashSet<Integer> res= new HashSet<Integer>();
        String num= String.valueOf(n);
        for (int i = 0; i < num.length() - 1; i++) {
            num= num.substring(num.length() - 1) + num.substring(0, num.length() - 1);
            res.add(Integer.parseInt(num));
        }
        return res;
    }
}