import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

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

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.StringTokenizer;

/**
 *
 * @author parusnik
 */
public class Codejam {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("input.txt"));
        BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt"));
        
        int T = Integer.parseInt(br.readLine());
        StringTokenizer st;
        String s1, s2;
        
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        
        for (int t = 1; t<=T; t++){
            
            bw.write("Case #" + String.valueOf(t) + ": ");
            
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            
            long d = 0;
            
            map.clear();
            
            for (int i = a; i<=b; i++){
                String s = String.valueOf(i);
                String str = s;
                for (int k = 0; k<10; k++){
                    s = s.substring(1, s.length()) + s.substring(0, 1);
                    str = min (str, s);
                }
                int x = 0;
                if (map.containsKey(str)) x = map.get(str);
                map.put(str, x+1);
            }
            
            Collection<Integer> col = map.values();
            for (Integer i : col) {
                d+=(long) (i)*(i-1)/2;
            }
            
            bw.write(String.valueOf(d));
            
            bw.newLine();
        }
        
        br.close();
        bw.close();
    }
    
    static String min(String s1, String s2){
        if (Integer.parseInt(s1)<Integer.parseInt(s2)) return s1; else return s2;
    }
}
