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

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

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author 3mara
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    static int testCases = 0;
    static int a = 0, b = 0;
    static int numDigits;
    static HashMap<Integer, HashMap<Integer, Integer>> table = new HashMap<Integer, HashMap<Integer, Integer>>();

    public static void read() {
        try {
            int index = 1;
            BufferedReader br = new BufferedReader(new FileReader("C-small-attempt0.in"));
            int result = 0;
            testCases = Integer.parseInt(br.readLine());
            while (index <= testCases) {
                String array = (br.readLine());
                a = Integer.parseInt((array.split(" "))[0]);
                b = Integer.parseInt((array.split(" "))[1]);
                numDigits = (array.split(" ")[0]).length();
                if (a == (b) || a < 9) {
                    System.out.println("Case #" + index + ": 0");
                } else {
                    result = 0;
                    table.clear();
                    String temp = "";
                    for (int i = a; i <= b; i++) {
                        for (int j = numDigits - 1; j >= 1; j--) {
                            temp = i + "";
                            int tempint = Integer.parseInt(temp.substring(j) + temp.substring(0, j));
                            if ((tempint <= b) && tempint > i) {
                                if (table.get(i) != null && !table.get(i).containsKey(tempint)) {
//                                System.out.println(temp + "====" + temp.substring(j) + temp.substring(0, j));
                                    result++;
                                } else if (table.get(i) == null) {
                                    table.put(i, new HashMap<Integer, Integer>());
                                    table.get(i).put(tempint, 1);
                                    result++;
                                }
                            }
                        }
                    }
                    System.out.println("Case #" + index + ": " + result);
                }


                index++;
            }
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void main(String[] args) {
//        try {
//            BufferedReader br = new BufferedReader(new FileReader("a.txt"));
//            String[] array = new String[288];
//            String line = "";
//            int i = 0;
//            while ((line = br.readLine()) != null) {
//                array[i] = line;
//                i++;
//            }
//            Arrays.sort(array);
//            for (int j = 0; j < 288; j++) {
//                System.out.println(array[j]);
//            }
//            //        System.out.println();
//            //        System.out.println();
        read();
//            //        System.out.println();
//        } catch (IOException ex) {
//            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
//        }
    }
}
