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.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Scanner;


public class C {
	
	public static void main(String[] args) {
		
		try {
			Scanner in = new Scanner(new File("C.in"));
			BufferedWriter writer = new BufferedWriter(new FileWriter(new File("C.out")));
			
			int T = in.nextInt();
			in.nextLine();
			
			for (int i=0; i<T; i++) {
				
				int A = in.nextInt();
				int B = in.nextInt();
				
				long res = 0;
				
				for (int X=A; X<B; X++) {
					
					int D = digits(X);
					HashSet<Integer> set = new HashSet<Integer>();
					
					for (int j=1; j<D; j++) {
						int C = moveLast(X, j);
						
						if (C > X && C <= B && !(set.contains(C))) {
							set.add(C);
							res++;
							//System.out.println("X="+X + ",     C="+C);
						}
					}
				}
				
				writer.append("Case #" + (i+1) + ": " + res + "\n");
			}
			
			writer.close();
			
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static int moveLast(int X, int digits) {
		
		int last = 0;
		int p = 1;
		int p2 = 1;
		
		for (int i=0; i<digits; i++) p *= 10;
		
		last = X % p;
		
		while ((p2*10)<=X) p2 *= 10;
		
		return last*(p2/p)*10 + (X / p); 
	}
	
	public static int digits(int X) {
		int k = 0;
		
		while (X > 0) {
			X /= 10;
			k++;
		}
		
		return k;
	}
}
