import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class C{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int caze, T;
	int A, B;

	void run(){
		T=sc.nextInt();
		for(caze=1; caze<=T; caze++){
			A=sc.nextInt();
			B=sc.nextInt();
			solve();
		}
	}

	void solve(){
		int ans=0;
		for(int n=A; n<=B; n++){
			int digit=(int)(log10(n)+EPS);
			int d=(int)pow(10, digit);
			// debug("n", n);
			for(int m=rot(n, d); m!=n; m=rot(m, d)){
				// debug("m", m);
				if(n<m&&m<=B){
					ans++;
				}
			}
		}
		answer(ans+"");
	}

	int rot(int n, int d){
		return n/10+n%10*d;
	}

	void answer(String s){
		println("Case #"+caze+": "+s);
	}

	void println(String s){
		System.out.println(s);
	}

	void print(String s){
		System.out.print(s);
	}

	void debug(Object... os){
		System.err.println(deepToString(os));
	}

	public static void main(String[] args){
		try{
			System.setIn(new FileInputStream("dat/C-small.in"));
			System.setOut(new PrintStream(new FileOutputStream("dat/C-small.out")));
		}catch(Exception e){}
		new C().run();
		System.out.flush();
		System.out.close();
	}
}

import java.io.*;
import java.util.*;
public class q3{
    
    public static int fact(int t){
	int result = 1;
	if(t < 1)
	    return 0;
	for(int i = 1; i <= t; i++){
	    result *= i;
	}
	return result;
    }
	    
    
    public static int choose(int n, int m){
	if(m > n)
	    return 0;
	if(m == n)
	    return 1;
	int result = fact(n)/(fact(m) * fact(n-m));
	return result;
    }
	
    
    public static int shift(int num){
	String intNum = Integer.toString(num);
	String shifted = intNum.substring(1) + intNum.substring(0,1);
	int shiftedNum = Integer.parseInt(shifted);
	return shiftedNum;
    }
    
    public static String shiftS(String num){
	String shifted = num.substring(1) + num.substring(0,1);
	return shifted;
    }
    
    
    public static void main (String[] args) throws IOException 
    {
	BufferedReader input = new BufferedReader (new FileReader ("C-small-attempt0.txt"));
	PrintWriter output = new PrintWriter (new FileWriter("test3Done.out"));
	StringTokenizer st;
	
	int numLines = Integer.parseInt(input.readLine());
	for(int i = 0; i < numLines; i++){
	    st = new StringTokenizer(input.readLine());
	    int A = Integer.parseInt(st.nextToken());
	    int B = Integer.parseInt(st.nextToken());
	    int counter = 0;
	    
	    boolean [] numbers = new boolean[B+1];
	    
	    for(int j = 0; j < B+1; j++){
		numbers[j] = true;
	    }
	    
	    for(int j = A ; j < B + 1; j++){
		int uniqueR = 0;
		if(numbers[j]){
		    String currNumS = Integer.toString(j);
		    int currNum = j;
		    numbers[j] = false;
		    for(int k = 0; k < Integer.toString(j).length() - 1; k++){
			if(Integer.parseInt(shiftS(currNumS)) <= B && Integer.parseInt(shiftS(currNumS)) >= A && shiftS(currNumS).charAt(0) != '0'){
			    if(numbers[Integer.parseInt(shiftS(currNumS))]){
				uniqueR ++;
				numbers[Integer.parseInt(shiftS(currNumS))] = false;
			     }
			}
			currNumS = shiftS(currNumS);
		    }
		    counter += choose(uniqueR+1,2);
		}
	    }
	    
	    output.println("Case #" + (i+1) + ": " + counter);
	}
	output.close();
    }
}
			     
			    
			
	    
	    
	    
	    
