import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class C{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int caze, T;
	int A, B;

	void run(){
		T=sc.nextInt();
		for(caze=1; caze<=T; caze++){
			A=sc.nextInt();
			B=sc.nextInt();
			solve();
		}
	}

	void solve(){
		int ans=0;
		for(int n=A; n<=B; n++){
			int digit=(int)(log10(n)+EPS);
			int d=(int)pow(10, digit);
			// debug("n", n);
			for(int m=rot(n, d); m!=n; m=rot(m, d)){
				// debug("m", m);
				if(n<m&&m<=B){
					ans++;
				}
			}
		}
		answer(ans+"");
	}

	int rot(int n, int d){
		return n/10+n%10*d;
	}

	void answer(String s){
		println("Case #"+caze+": "+s);
	}

	void println(String s){
		System.out.println(s);
	}

	void print(String s){
		System.out.print(s);
	}

	void debug(Object... os){
		System.err.println(deepToString(os));
	}

	public static void main(String[] args){
		try{
			System.setIn(new FileInputStream("dat/C-small.in"));
			System.setOut(new PrintStream(new FileOutputStream("dat/C-small.out")));
		}catch(Exception e){}
		new C().run();
		System.out.flush();
		System.out.close();
	}
}

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		
		
		//BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("c:\\input.txt")));
		int cases = Integer.parseInt(reader.readLine());
		for(int i=0; i<cases; i++){
			String inputString = reader.readLine();		
			StringTokenizer st = new StringTokenizer(inputString);
			
			int numOfRecycledPairs = 0;
			int A = Integer.parseInt(st.nextToken());
			int B = Integer.parseInt(st.nextToken());
			int numOfDigits = Integer.toString(A).length();
			
			HashSet<Integer> processedNumber = new HashSet<Integer>();
			//System.out.println(A + " " + B);
			for(int a=A; a<=B; a++) {

				if(processedNumber.contains(a) || isAllTheSameDigits(a))
					continue;

				
				processedNumber.add(a);
				int eligibleNumbers = 1;
				int numberToProcessed = a;
				//System.out.print("numberToProcessed:" + numberToProcessed +",");
				for(int j=0; j<numOfDigits-1; j++) {
					numberToProcessed = shift(numOfDigits, numberToProcessed);
					//System.out.print("numberToProcessed:" + numberToProcessed);
					if(isCandidate(A, B, processedNumber, numberToProcessed)) {
						processedNumber.add(numberToProcessed);
						++eligibleNumbers;
					}
				}
				//System.out.println("");
				
				numOfRecycledPairs += (eligibleNumbers*(eligibleNumbers-1)/2);
				
			}
			
			System.out.println("Case #"+(i+1)+": "+numOfRecycledPairs);
		}

	}
	
	public static boolean isAllTheSameDigits(int number) {
		String sNumber = Integer.toString(number);
		char digits[] = sNumber.toCharArray();
			
		char significatDigits = digits[0];
		for(int i=1; i<digits.length; i++) {
			if(digits[i]!= significatDigits )
				return false;
		}
		return true;
	}
	
	public static int shift(int numOfDigits, int number) {
		return (int)((number%10)*Math.pow(10, numOfDigits-1)) + number/10;
	}
	
	public static boolean isCandidate(int A, int B, HashSet<Integer> processedNumber, int number) {
		if(number >=A && number <=B && !processedNumber.contains(number))
			return true;
		else
			return false;
	}

}
