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.InputStreamReader;

public class main {

	public static void main(String[] args) {
		// inputãã¡ã¤ã«ãèª­ã¿è¾¼ã¿
		BufferedReader bufferReader = null;
		String str = "";
		try {
			bufferReader = new BufferedReader(new InputStreamReader(
					new FileInputStream("/Users/yago/Documents/in.txt"),
					"UTF-8"));
			// ä¸è¡ãã¤èª­ã¿è¾¼ã¿
			int probs = 0;
			while ((str = bufferReader.readLine()) != null) {
				if (str.length() > 2) {
					probs++;
					calc(str, probs);
				}
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		} finally {
			try {
				if (bufferReader != null) {
					bufferReader.close();
				}
			} catch (Exception e) {
			}
		}
	}

	private static void calc(String str, int probNum) {
		Integer n1, n2, ansCnt = 0;
		String[] strAry = str.split(" ");
		n1 = Integer.valueOf(strAry[0]);
		n2 = Integer.valueOf(strAry[1]);
		for (int i = n1; i <= n2; i++) {
			for (int j = i + 1; j <= n2; j++) {
				if(String.valueOf(j).length() == 1)
					break;
				if (String.valueOf(j).length() == 2) {
					if (String.valueOf(j).charAt(0) == String.valueOf(i)
							.charAt(1)
							&& String.valueOf(j).charAt(1) == String.valueOf(i)
									.charAt(0))
						ansCnt++;
				} else if ((String.valueOf(j).charAt(0) == String.valueOf(i)
						.charAt(1)
						&& String.valueOf(j).charAt(1) == String.valueOf(i)
								.charAt(2) && String.valueOf(j).charAt(2) == String
						.valueOf(i).charAt(0))
						|| String.valueOf(j).charAt(0) == String.valueOf(i)
								.charAt(2)
						&& String.valueOf(j).charAt(1) == String.valueOf(i)
								.charAt(0)
						&& String.valueOf(j).charAt(2) == String.valueOf(i)
								.charAt(1)) {
					ansCnt++;
				}
			}
		}

		System.out.println("Case #" + probNum + ": " + ansCnt);
	}
}