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.*;
import java.util.Set;
import java.util.HashSet;

public class recycled {
	public static int A,B;
	public static int[] t = {1,10,100,1000,10000,100000,1000000,10000000};
	
	public static int solve(){
		if(B<10) return 0;
		int DB=0,kit,m,n;
		
		int lg = 0;
		while(lg < 6 && A >= t[lg+1]) lg++; 
		//System.out.println(A+" "+lg);
		
		for(n = A; n <B; n++){
			kit = 1;
			Set H = new HashSet();
			while(t[kit] < n){
				m = t[lg-kit+1]*(n%t[kit])+(n/t[kit]);
				//System.out.println("testing >>> "+n+" - "+m);	
				if( n < m && m <= B && (n%t[kit])*10>=t[kit] && !H.contains(m)) {
					
					DB++;
					H.add(m);
					//System.out.println("OK >>> "+n+" - "+m+" DB= "+DB);	
				}
				kit++;
			}
		}
		return DB;
	}
	
	public static void main (String args[]) throws IOException{
		
		
		BufferedReader be = new BufferedReader(new FileReader("C-large.in"));
		int T = Integer.parseInt(be.readLine());
		for(int i=1; i<=T; i++){
			String s = be.readLine();
			A = Integer.parseInt(s.split(" ")[0]);
			B = Integer.parseInt(s.split(" ")[1]);
			System.out.println("Case #"+i+": "+solve());
		}
		be.close();
	}
}

