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.*;
import java.util.*;
import java.lang.*;

class Pair {
	public int x;
	public int y;
	
	public Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}
	
	public static boolean equals(Pair a, Pair b) {
		return (((a.x == b.x) && (a.y == b.y)) || ((a.x == b.y) && (a.y == b.x)));
	}
}

public class Recycle {
	private static HashMap<Integer, HashSet<Integer>> map;
	public static void main(String[] args) throws IOException {		
		BufferedReader br = new BufferedReader(new FileReader(new File("/Users/atai/Play/Codejam/input.txt")));
		PrintWriter prn = new PrintWriter(new FileWriter("output.txt"));
		
		int numTests = Integer.parseInt(br.readLine().trim());
		for (int i = 0; i < numTests; i++) {
			String[] arg = br.readLine().trim().split(" ");
			int min = Integer.parseInt(arg[0]);
			int max = Integer.parseInt(arg[1]);
			
			int total = 0;
			map = new HashMap<Integer, HashSet<Integer>>();
			for (int j = min; j <= max; j++) {
				// for each number check to see how many pairs there are
				Integer rand = new Integer(j);
				int len = rand.toString().length();
				int stock = (int)Math.pow(10,len);
				for (int k = 0; k < len-1; k++) {
						int c = (int)Math.pow(10,k+1);
						int r = j % c;
						if (r == 0)
							continue;
						// leading zero?
						if (r < (int)Math.pow(10,k))
							continue;
						
						int recycle = (j+stock*r)/c;
						if ((recycle > j) && (recycle <= max)) {
							System.out.println(j + ", " + recycle);
							if (map.containsKey(j)) {
								if (map.get(j).add(recycle))
									total++;
							} else {
								HashSet<Integer> temp = new HashSet<Integer>();
								temp.add(recycle);
								map.put(j, temp);
								total++;
							}
						}
				}						
			}
			prn.printf("Case #%d: %d\n", i+1, total);
		}
		
		prn.close();
	}
}
