import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;


public class Test {

	public static void main(String[] args){
		FileInputStream fstream = null;
		DataInputStream in = null;
		BufferedReader br = null;
		FileWriter fw = null;
		BufferedWriter out = null;
		
		try{
			  fstream = new FileInputStream(args[0]);
			  in = new DataInputStream(fstream);
			  br = new BufferedReader(new InputStreamReader(in));
			  
			  fw = new FileWriter(args[1]);
			  out = new BufferedWriter(fw);
			  
			  String strLine;
			  int i = 0;
			  int tc = 0;
			 
			  while ((strLine = br.readLine()) != null)   {
				  if(i == 0){
					 tc = Integer.parseInt(strLine);
					 i++;
					 continue;
				  }
				  if( i <= tc){
					  String[] arr = strLine.split(" ");
					  int minLimit = Integer.parseInt(arr[0]);
					  int maxLimit = Integer.parseInt(arr[1]);
					  int count = 0;
					  int len = arr[0].length();
					  if(len <= 1){
						  count = 0;
					  }else{
						  for(int j = minLimit; j <= maxLimit ; j++){
							  int num = j;
							  List ls = new ArrayList();
							  for(int k = 1; k < len ; k++ ){
								  int dp = (int)Math.pow(10, len -k);
								  int mp = (int)Math.pow(10, k);
								  int first = num / dp;
								  int last = num % dp;
								  int number = last*mp + first;
								  
								  if(num != number){
									  if(number <= maxLimit && number >= minLimit){
										  if(!ls.contains(number+"")){
											  ls.add(number+"");
											  count++;
										  }
										 
									  }
								  }
								  
							  }
						  }
					  }
					  count = count/2;
					  System.out.println("Case #"+i+": "+count);
					  out.write("Case #"+i+": "+count);
					  out.write(System.getProperty( "line.separator" ));
				  }
				  i++;
			  }
			  
			  in.close();
			  out.close();
		}catch (Exception e){
			e.printStackTrace();
			System.err.println("Error: " + e.getMessage());
		}
	}
	
	
}


