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.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public class R1P3 {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {

		BufferedReader in = new BufferedReader(new FileReader("C-small-attempt0.in"));
		BufferedWriter bw = new BufferedWriter(new FileWriter("small3.out"));
		String inLine;
		int t = Integer.parseInt(in.readLine());
		int counter = 0;
		while ((inLine = in.readLine()) != null) {
			counter++;
			String[] toks = inLine.split(" ");
			long beg = Long.parseLong(toks[0]);
			long end = Long.parseLong(toks[1]);
			long c = 0;
			for (long i = beg; i < end; i++) {
				c += rotateNumber(i, end);
			}
			System.out.println("Case #" + counter + ": " + c);
			bw.write("Case #" + counter + ": " + c);
			bw.newLine();
		}
		in.close();
		bw.close();
	}

	public static long rotateNumber(long number, long end) {
		long start = number;
		int numdigits = (int) Math.log10((double) number); // would return
															// numdigits - 1
		int multiplier = (int) Math.pow(10.0, (double) numdigits);
		long counter = 0;
		while (true) {
			long q = number / 10;
			long r = number % 10;
			number = number / 10;
			number = number + multiplier * r;
			if (start < number && number <= end)
				counter++;
			if (number == start)
				break;
		}
		return counter;
	}

}
