import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

public class Recycled {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int t = Integer.parseInt(br.readLine());
            for (int i = 0; i < t; i++) {
                String[] str = br.readLine().split(" ");
                int a = Integer.parseInt(str[0]);
                int b = Integer.parseInt(str[1]);
                System.out.println("Case #" + (i + 1) + ": " + find(a, b));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static int find(int a, int b) {
        HashSet<Long> used = new HashSet<Long>();
        int digits = String.valueOf(a).length();
        if (digits == 1) return 0;
        for (int i = a; i <= b; i++) {
            int s = 10;
            int m = (int) Math.pow(10, digits-1);
            for (int j = 0; j < digits-1; j++) {
                int r = i % s;
                if (r < s/10) continue;
                int q = i / s;
                int rn = r * m + q;
                s *= 10; m /= 10;
                if (i != rn && rn >= a && rn <= b) {
                    long pp;
                    if (rn < i) pp = (long)rn << 30 | i;
                    else pp = (long)i << 30 | rn;
                    if (!used.contains(pp)) {
                        used.add(pp);
                    }
                }
            }
        }
        return used.size();
    }
}


package Qualification;
import Practice.*;
import java.util.*;
import java.io.*;

public class C {
    
    public void ejecutar() throws Exception {
        Scanner sc = new Scanner(new FileReader("/home/gomezluisj/Descargas/C-large.in"));
	PrintWriter pw = new PrintWriter(new FileWriter("/home/gomezluisj/Descargas/C.out"));
	int caseCnt = sc.nextInt();
        for (int caseNum = 0; caseNum < caseCnt; caseNum++) {
            pw.print("Case #" + (caseNum + 1) + ": ");
            int ini=sc.nextInt();
            int fin=sc.nextInt();
            int res=0;
            for (int i = ini; i < fin; i++) {
                String number=Integer.toString(i);
                List<Integer> lista=new ArrayList<Integer>();
                for (int j = 1; j < number.length(); j++) {
                    String compare=number.substring(j)+number.substring(0, j);
                    
                    int num=Integer.parseInt(compare);
                    if(num>i&&num<=fin){
                        Iterator iter=lista.iterator();
                        int flag=0;
                        while(iter.hasNext()){
                            if((Integer)iter.next()==num){
                                flag=1;
                            }
                        }
                        if (flag==0){
                            res=res+1;
                            lista.add(num);
                        }
                        
//                        System.out.println(""+i+" "+num);
                    }
                }
            }
            pw.println(res);
        }	
        pw.flush();
        pw.close();
        sc.close();
    }
    
    
    public static void main(String[] args) throws Exception {
		new C().ejecutar();
	}
}
