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

			}
		}

	}
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;


public class recycle {

    
    public static void rec() throws NumberFormatException, IOException {
        BufferedReader in = new BufferedReader(new FileReader("src/test1")); 

        String line;
        StringBuilder bubs = new StringBuilder();


        int T = Integer.parseInt(""+in.readLine().charAt(0));

        int i=0;
        while ((line=in.readLine())!=null) {
            i++;
            String[] splitline = line.split("\\s+");
            
            int A = Integer.parseInt(splitline[0]);
            int B = Integer.parseInt(splitline[1]);
            int d = splitline[0].length();

            StringBuilder subs = new StringBuilder();
            subs.append("Case #" + i + ": ");
            int count = 0;

            for (int n=A;n<B;n++) {
                String sn = ""+n;
                HashMap<Integer, Integer> hm = new HashMap();

                for (int b=0;b<d-1;b++) {
                    String r = sn.substring(d-1-b);
                    String l = sn.substring(0, d-1-b);
                    String btry = (r+l);
                    if (!hm.containsKey(Integer.parseInt(btry)) && btry.charAt(0)!='0' && Integer.parseInt(btry) > n && Integer.parseInt(btry) <=B) {
                        hm.put(Integer.parseInt(btry), 1);
                        count++;
            
                    }
                    
                }

            }
            subs.append(count);
            bubs.append(subs.toString());
            System.out.println(subs.toString());
        }
        

    }
    
}
