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

public class prob2 {
	public static void main(String[] args) {
		BufferedReader inputStream = null;
		try {
			inputStream = new BufferedReader(new FileReader(
					"C:/Users/vpamarty.SYMPHONY/Downloads/C-small-attempt1.in"));
			String lineRead = inputStream.readLine();

			int noCases = Integer.valueOf(lineRead).intValue();
			for (int i = 0; i < noCases; i++) {
				lineRead = inputStream.readLine();
				String[] splitString = lineRead.split(" ");
				int numA = Integer.valueOf(splitString[0]).intValue();
				int numB = Integer.valueOf(splitString[1]).intValue();

				int distinctRps = computeDisRps(numA, numB);
				System.out.println("Case #"+(i+1)+": "+distinctRps);
			}
			inputStream.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static int computeDisRps(int num1, int num2) {
		int numPairs = 0;
		for (int numCons = num1; numCons < num2; numCons++) {
			int numLength = (String.valueOf(numCons)).length();
			ArrayList<String> numArr = new ArrayList<String>();
			numArr.add(String.valueOf(numCons));
			for (int i = 1; i < numLength; i++) {
				String numString = String.valueOf(numCons);
				String newNumString = numString.substring(numLength - i)
						+ numString.substring(0, numLength - i);
				if (!numArr.contains(newNumString)) {
					numArr.add(newNumString);
					if (Integer.valueOf(newNumString).intValue() > numCons
							&& Integer.valueOf(newNumString).intValue() <= num2)
						numPairs++;
				}
			}
		}
		return numPairs;

	}
}
