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.*;
import java.util.*;

public class Pairing{

	public static void main(String args[]){
		try
		{
  			FileInputStream fstream = new FileInputStream("textfile.txt");
			DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			FileWriter ffstream = new FileWriter("./output.txt");
		  	BufferedWriter out = new BufferedWriter(ffstream);
			String strLine,result;
			int i=0;
			strLine = br.readLine();
			i=Integer.parseInt(strLine);
			String startS, endS;
			int j=1;
			int val=0;
			int start=0,end=0,tt=0;
			int count=0;
			PairList lista;
			Pair res;
			while (j<=i)   {
				lista = new PairList();
				count=0;
				strLine = br.readLine();
				StringTokenizer token = new StringTokenizer(strLine);
				startS = token.nextToken();

	
				start=Integer.parseInt(startS);
				endS = token.nextToken();
			
	
				end=Integer.parseInt(endS);

				char[] startA = startS.toCharArray();
				char[] endA = endS.toCharArray();
				char[] temp = new char[endA.length];
				char[] newn = new char[endA.length];
				int curr=start;
				boolean adding=false;
				if(startA.length==endA.length && startA.length>1){
					int stop=start+(end-start)/2+1;
					while(curr<=end){
						curr++;

						temp = Integer.toString(curr).toCharArray();
						int k=temp.length-1;
						while(k>0){

							if(temp[k]<=endA[0] && temp[k]>=startA[0]){
								int l = k;
								int m=0;
								while(l<=temp.length-1){
									newn[m]=temp[l];
									l++;
									m++;

								}
								l = 0;
								while (m<temp.length){
									newn[m]=temp[l];
									l++;
									m++;
								}		
								result = new String(newn);
								res = new Pair();
								tt = Integer.parseInt(result);

								if(tt<curr && curr<=end && tt>=start){
									res.first=tt;
									res.second=curr;
									adding = true;
								}
								else if(tt>curr && tt<=end && curr>=start){ 
									res.first=curr;
									res.second=tt;
									adding=true;
								}
								else adding=false;
								
								
								if(adding==true ){
									int place = lista.Find(res,end);
									if(place<end){
										count++;
										lista.addP(place,res);
									}
								}
							}
							k--;
						}
					}
					
					
				}

				out.write("Case #"+Integer.toString(j)+": "+Integer.toString(count)+"\n");
				j++;
			}
			
			in.close();
			out.close();
		}
		catch (Exception e){//Catch exception if any
			e.printStackTrace();
		}
	}

}

