import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

	}
	
	
}
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.*;

/**
 *
 * @author virginia
 *
 */
public class RecycledNumbers {
	public static int countn(int v)
	{
		int count=0;
		while (v> 0 && count<10 )
			{
				   int r = v % 10;
					count++;
				   v = v / 10;
	        }
	        return count;
		}
 public static void main(String[] args) {

 try {
   BufferedReader br = new BufferedReader(new FileReader("C-small-attempt1.in"));
   BufferedWriter output=new BufferedWriter(new FileWriter("Output.txt"));
  PrintWriter pw = new PrintWriter(output);

int n = Integer.parseInt(br.readLine());
 int[][] result = new int[n][2];

 String line;
 int a= 0;
 while ((line = br.readLine()) != null) {
  String[] tokens = line.split("\\s");

  for (int j = 0; j <2; j++) {
   result[a][j] = Integer.parseInt(tokens[j]);
  }

  a++;
 }
    int index = 0;

   for(int i =0; i < n; i++)
   {
	    int found=0;
								index++;
							   int A=result[i][0];
							   int B=result[i][1];
							   for(int j=A;j<=B;j++)
							   {
											  int cnt=0;
											  int num=j;
											  int rev=0;
												while (num> 0 && cnt<10 )
												{
													   int r = num % 10;
														cnt++;
													   num = num / 10;

												}
												int num1=j;
												int num2=j;
												int p=cnt-1;
												int r=0;
												do
												{
													cnt--;
													int s=(num1)%10;
													num2=num2/10;
													num1=(int)(s*Math.pow(10,(p)))+(num2);

													num2=num1;

													if(RecycledNumbers.countn(j)==RecycledNumbers.countn(num1))
													{
													if((A<=j)&&(j<num1)&&(num1<=B))
													{


														 found++;
												}}
												 }while(cnt>0);
								  }
   pw.print("Case #" + index + ": ");
   pw.println(found);
   System.out.print("Case #" + index + ": ");
   System.out.println(found);
   }
   output.close();
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
}
