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.util.*;
import java.io.*;
import static java.lang.Math.*;

public class A {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader in = new BufferedReader(new FileReader("C-small-attempt0.in"));
  		FileWriter fw = new FileWriter("output.out");
  		/*BufferedReader in = new BufferedReader(new FileReader("A-large.in"));
  		FileWriter fw = new FileWriter("A-large.out");*/
  		int N = new Integer(in.readLine());
  		String[] output = new String[N];
  		int[] trueCount = new int[N];
  		for (int cases = 0; cases < N; cases++) {
  			int CaseNo = cases+1;
  			output[cases] = "";
  			StringTokenizer G = new StringTokenizer(in.readLine());
  			int W = G.countTokens();
  			int[] a = new int[2];
  			String[] b = new String[W];
  			for (int j = 0; j < a.length; j++) {
  				a[j] = new Integer(G.nextToken());
  			}
  			int counter = 1;
  			int A =a[0];
  			int B =a[1];
  			int C = a[0];
  			System.out.println(A + "  x  " +B);
  			
  			int lengthA = Integer.toString(A).length();
  			if (lengthA == 1){
  				trueCount[cases] = 0;
  			}
  			else{
	  			int range = B - A + 1;
	  			int[] rangeA = new int[range];
	  			rangeA[0] = A;
	  			while (A<B){
	  				A = A+1;
	  				rangeA[counter] = A;
	  				counter=counter+1;
	  			}
	  			for (int ii=0;ii<range;ii++){
	  				int currentN = rangeA[ii];
	  				int currentM = rangeA[ii];
	  				int length = Integer.toString(rangeA[ii]).length();
	  				String curM = Integer.toString(currentM);
	  				for (int jj=0; jj<length;jj++){  					
	  					curM = curM.charAt(length-1) + curM.substring(0, length-1);
	  					currentM = Integer.parseInt(curM);	  					
	  					if (currentM <= B && currentM > currentN && currentM >= C){
	  						trueCount[cases]+=1;
	  					}
	  				}
	  				
	  			}  	
  			}
  			fw.write("Case #"+CaseNo+": "+ trueCount[cases]+ "\n");  			
  			
  		}
  		fw.flush();
  		fw.close();
	}
}
