import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Recycled {
	public static void main(String[] args) throws Exception{
		String inputFile = "C-small-attempt0.in";
		
		BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
		BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output")));
		long num_cases = Long.parseLong(input.readLine());
		int current_case = 0;
		
		while (current_case < num_cases){
			current_case++;
			
			String[] fields = input.readLine().split(" ");
			int A = Integer.parseInt(fields[0]);
			int B = Integer.parseInt(fields[1]);
			int total = 0;
			
			for (int n = A; n < B; n++){
				for (int m = n+1; m <= B; m++){
					if (isRecycled(n,m)) total++;
				}
			}
			
			System.out.println("Case #" + current_case + ": " + total);
			output.write("Case #" + current_case + ": " + total + "\n");
		}
		output.close();
	}

	private static boolean isRecycled(int n, int m) {
		String sn = ""+n;
		String sm = ""+m;
		if (sn.length() != sm.length()) return false;
		int totaln = 0, totalm = 0;
		for (int i = 0; i < sn.length(); i++){
			totaln += sn.charAt(i);
			totalm += sm.charAt(i);
		}
		if (totaln != totalm) return false;
		for (int i = 0; i < sn.length()-1; i++){
			sm = sm.charAt(sm.length() - 1) + sm.substring(0, sm.length() - 1);
			if (sm.equals(sn)) return true;
		}
		return false;
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


public class Numbers {
	
	private static int [][] input;
	private static int [] output;
	
	public static void main(String [] args) throws NumberFormatException, IOException{
		
		readData();
		output = new int [input.length];
		
		for (int i=0 ; i< input.length ; i++){
			output[i] = numberOfPairs(input[i][0], input[i][1]);
		}
		
		writeData();
	}

	public static int numberOfPairs(int a, int b){
		int r=0;
		for (int i=a ; i<=b;i++ ){
			int f = flip(i);
			if ( i<f && a<=f && f<=b ){
				r++;
				}
			if (i>100){
				int f2 = flip2(i);
				if (( i<f2 && a<=f2 && f2<=b )){
					r++;
				}
			}
			
		}
		return r;
		
	}
	
	public static int flip(int i){
		
		String A = Integer.toString( i );
		String ans = A.substring( 1)+ A.substring( 0, 1 );
		return Integer.parseInt( ans );
	
	}
	public static int flip2(int i){
	
	String A = Integer.toString( i );
	String ans = A.substring( 2)+ A.substring( 0, 2 );
	return Integer.parseInt( ans );

	}
	
	public static void readData() throws NumberFormatException, IOException{
		FileReader fr = new FileReader("Input.txt");
		BufferedReader br = new BufferedReader(fr);
		int numberOfInputs = Integer.parseInt( br.readLine() );
		input = new int [numberOfInputs][2];
		for (int i = 0; i<numberOfInputs ; i++  ){
			String [] numbers = ((String)(br.readLine())).split( " " );   
			for (int j = 0 ; j<2 ;j++){
				input [i][j] =  Integer.parseInt(numbers [j]);
			}
		}
		br.close();
	}
	
	public static void writeData() throws IOException{
		FileWriter fw = new FileWriter("Output.txt");
		BufferedWriter bw = new BufferedWriter(fw);
		for (int i = 0; i< output.length ; i++ ){
			String out = "Case #" +(i+1) +": "+ output[i];
			bw.write( out );
			bw.newLine();
		}
		bw.close();
	}
}
