import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Recycled {
	public static void main(String[] args) throws Exception{
		String inputFile = "C-small-attempt0.in";
		
		BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
		BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output")));
		long num_cases = Long.parseLong(input.readLine());
		int current_case = 0;
		
		while (current_case < num_cases){
			current_case++;
			
			String[] fields = input.readLine().split(" ");
			int A = Integer.parseInt(fields[0]);
			int B = Integer.parseInt(fields[1]);
			int total = 0;
			
			for (int n = A; n < B; n++){
				for (int m = n+1; m <= B; m++){
					if (isRecycled(n,m)) total++;
				}
			}
			
			System.out.println("Case #" + current_case + ": " + total);
			output.write("Case #" + current_case + ": " + total + "\n");
		}
		output.close();
	}

	private static boolean isRecycled(int n, int m) {
		String sn = ""+n;
		String sm = ""+m;
		if (sn.length() != sm.length()) return false;
		int totaln = 0, totalm = 0;
		for (int i = 0; i < sn.length(); i++){
			totaln += sn.charAt(i);
			totalm += sm.charAt(i);
		}
		if (totaln != totalm) return false;
		for (int i = 0; i < sn.length()-1; i++){
			sm = sm.charAt(sm.length() - 1) + sm.substring(0, sm.length() - 1);
			if (sm.equals(sn)) return true;
		}
		return false;
	}
}

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

/**
 * Created by IntelliJ IDEA.
 * User: marcus
 * Date: 4/14/12
 * Time: 1:57 PM
 * To change this template use File | Settings | File Templates.
 */
public class RecycledNumbers {
    
    public static void main(String a[]) throws IOException {


        FileInputStream fInputstream = null;
        try {
            fInputstream = new FileInputStream("C-small.in");
        } catch (FileNotFoundException e) {
            //e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        DataInputStream in = new DataInputStream(fInputstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;

        FileWriter fstream = new FileWriter("C-small.out");
        BufferedWriter out = new BufferedWriter(fstream);

        String strT = null;
        strT = br.readLine();

        int T =  Integer.parseInt(strT);
        for(int d = 1; d <= T; d++)  {

            String testCase =  br.readLine();
            StringTokenizer st = new StringTokenizer(testCase, " ");

            int A = Integer.parseInt(st.nextToken());
            int B = Integer.parseInt(st.nextToken());

            int dev = 0;
            int base = 10;
            while ( dev == 0){
                if(A < base){
                    dev = base /10;
                } else
                    base *= 10;
            }

            int count = 0;
            Hashtable <String, Integer> table = new Hashtable <String, Integer>();

            for(int i = A; i <= B; i++){
                //System.out.println("i :" + i);
                int mul = 10;
                for(int j = dev; j > 1 ; j/= 10, mul *= 10){
                    //System.out.println("J :" + j);
                    int val = i / j;

                    int rem = i % j;
                    int recycledHalf = (rem * mul) + val;
                    //System.out.println("recycledHalf :" + recycledHalf);





                    if(A <= i && i < recycledHalf && recycledHalf <= B ) {
                        System.out.println(A + " <= " + i + " < " + recycledHalf + " <= " + B);
                        String s = String.valueOf(i) + "," + String.valueOf(recycledHalf);
                        //System.out.println( s );
                        table.put(s, new Integer(0));

                    }


                }

            }
            count = table.size();
            //System.out.println("Dev :" + dev);
            //System.out.println("Count :" + count);
            out.write("Case #" + d + ": " + count + "\n");

        }

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