import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
import java.io.*;
import java.util.Set;
import java.util.HashSet;

public class Recycler {
	public static void main(String[] args)
		throws IOException, FileNotFoundException {

		StreamTokenizer st = new StreamTokenizer(
				new FileReader(args[0]));

		FileWriter out = new FileWriter(args[1]);

		st.parseNumbers();
		if (st.nextToken() == StreamTokenizer.TT_EOF) eof_error();

		int numTestCases = (int) st.nval;
		int numDistinctPairs = 0;
		boolean twins = false;
		Set<Integer> partners = new HashSet<Integer>();

		for (int t = 0; t < numTestCases; ++t) {

			if (st.nextToken() == StreamTokenizer.TT_EOF) eof_error();
			int A = (int) st.nval;
			if (st.nextToken() == StreamTokenizer.TT_EOF) eof_error();
			int B = (int) st.nval;

			for (int i = A; i < B; ++i) {

				String curNumberString = String.valueOf(i);

				for(int j = 1; j < curNumberString.length(); ++j) {

					String sub1 = curNumberString.substring(j);
					String sub2 = curNumberString.substring(0, j);

					String test = sub1 + sub2;


					if (Integer.valueOf(test) > i &&
							Integer.valueOf(test) <= B) {

						if (! partners.contains(Integer.valueOf(test))) {
							++numDistinctPairs;
							partners.add(Integer.valueOf(test));
						}

					}

				}

				partners.clear();
			}
			out.write("Case #" + (t+1) + ": " + numDistinctPairs + "\n");
			numDistinctPairs = 0;
		}

		out.close();
	}

	private static void eof_error() {
		throw new RuntimeException("Unexpected end of file reached");
	}
}
