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.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.*;

public class Recycle {
	
	public int count(int start, int end) {
		int count = 0;
		HashSet<Integer> numbers = new HashSet<Integer>();
		int numDigits = (int)Math.log10(start) + 1;
		
		for(int i = start; i <= end; i++) {
			HashSet<Integer> rotations = getRotations(i, numDigits);
			for(int r : rotations) {
				if(numbers.contains(r)) {
					count++;
				}
			}
			numbers.add(i);
		}
		
		
		return count;
	}
	
	
	public HashSet<Integer> getRotations(int input, int numDigits) {
		HashSet<Integer> result = new HashSet<Integer>();
		for(int i = 0; i < numDigits - 1; i++) {
			int power = (int)Math.pow(10, i+1);
			int edge = input % power;
			result.add( (input - edge) / power + edge * (int)Math.pow(10, numDigits - i - 1) );
		}
		
		return result;
	}
	
	public static void main(String args[]) {
		Recycle c = new Recycle();
		String result[] = null;
		
		
		try {
			Scanner sc = new Scanner(new FileInputStream("C:/Users/Administrator/Downloads/C-large.in"));
			String line = sc.nextLine().trim();
			int cases = Integer.parseInt(line);
			result = new String[cases];
			for(int i = 0; i < cases; i++) {
				line = sc.nextLine().trim();
				String temp[] = line.split(" ");
				int start = Integer.parseInt(temp[0]);
				int end = Integer.parseInt(temp[1]);
			
				result[i] = "Case #" + (i+1) + ": " + c.count(start, end);
			}
			
		} catch(Exception e) {
			e.printStackTrace();
		}
		
		try {
			 FileWriter fstream = new FileWriter("C:/out.txt");
			 PrintWriter out = new PrintWriter(fstream);
			 
			 for(int i = 0; i < result.length; i++) {
				 out.println(result[i]);
			 }
			 out.close();
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
}
