import java.io.*;
import java.util.*;

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}

import java.io.*;
import java.util.*;

/**
 *
 * @author kronenthaler
 */
public class C {
	public static void main(String arg[]){
		try{
			Scanner in = new Scanner(new FileInputStream("c-large.in"));
			System.setOut(new PrintStream("c.out"));
			int T = in.nextInt();
			for(int cases=1;cases<=T;cases++){
				int A = in.nextInt();
				int B = in.nextInt();
				int count = 0;
				for(int i=A;i<B;i++){
					//numero de digitos de i;
					int aux = i;
					int d = 0;
					while(aux!=0){ aux/=10; d++; }
					Set<ArrayList<Integer>> map = new HashSet<ArrayList<Integer>>();
					for(int j=1;j<d;j++){
						aux = i;
						int buf = 0;
						int offset = 1;
						for(int k=0; k<j; k++, offset*=10){
							buf += (aux % 10)*offset;
							aux /= 10;
						}
						offset=1;
						for(int k=j;k<d;k++,offset*=10);
						
						int m = (buf*offset) + aux;
						if(i < m && m <= B){
							ArrayList<Integer> a = new ArrayList<Integer>();
							a.add(i);
							a.add(m);
							if(!map.contains(a)){
								count++;
								map.add(a);
							}
						}
					}
				}
				System.out.printf("Case #%d: %d\n", cases, count);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
