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.util.Scanner;


public class C_RecycledNumbers {

	static int[] bases = {0, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
	static int digits(int value) {
		int i = 0;
		for (; i < bases.length && value >= bases[i]; i++);
		return i;
	}
	
	static int shift(int value, int len) {
		int last = value % 10;
		return (int)(Math.pow(10, len - 1)) * last + (value / 10);
	}
	
	
	static int countRecycled(int value, int B) {
		int shifted = value;
		int len = digits(value);
		int[] cache = new int[len];
		int ck = 0;
out:	for (int i = 0; i < len - 1; i++) {
			shifted = shift(shifted, len);
			
			if (shifted > value && shifted <= B) {
				for (int j = 0; cache[j] != 0; j++)
					if (cache[j] == shifted)
						continue out;	
				//System.out.println("n=" + value + ", m=" + shifted);
				cache[ck++] = shifted;
			}
		}
		return ck;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		/*int A = 1;
		int B = 500;
		int count = 0;
		for (int val = A; val <= B; val++) {
			count += countRecycled(val, B);
		}
		System.out.println(count);*/
		
		Scanner scan = new Scanner(System.in);
		int test = scan.nextInt();
		for (int t = 1; t <= test; t++) {
			int A = scan.nextInt();
			int B = scan.nextInt();
			int count = 0;
			for (int val = A; val <= B; val++) {
				count += countRecycled(val, B);
			}
			System.out.println("Case #" + t + ": " + count);
		}
	}
}
