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

public class C {
	
	private static boolean isRecycledPair(int n, int m) {
		String sn = Integer.toString(n);
		String sm = Integer.toString(m);
		if(sn.length() != sm.length())
			return false;
		int l = sn.length();
		for(int i = l; --i >= 0; ) {
			if(sm.equals(sn.substring(i, l) + sn.substring(0, i)))
				return true;
		}
		return false;
	}
	
	private static long recycledNumbers(String s) {
		StringTokenizer st = new StringTokenizer(s);
		final int A = Integer.parseInt(st.nextToken());
		final int B = Integer.parseInt(st.nextToken());
		long r = 0;
		for(int n = A; n < B; n++) {
			char c[] = Integer.toString(n).toCharArray();
			for(int i = c.length; --i > 0; ) {
				char a = c[0];
				for(int j = 1; j < c.length; j++)
					c[j - 1] = c[j];
				c[c.length - 1] = a;
				if(c[0] != '0') {
					int m = Integer.parseInt(new String(c));
					if(m > n && m <= B)
						r++;
				}
			}
//			for(int m = n; ++m <= B; ) {
//				if(isRecycledPair(n, m))
//					r++;
//			}
		}
		return r;
	}
	
	public static void main(String args[]) throws Exception {
		//String fileName = "C.in";
		//String fileName = "C-small-attempt0.in";
		String fileName = "C-large.in";
		BufferedReader in = new BufferedReader(new FileReader(fileName));
		PrintStream out = new PrintStream(fileName.substring(0, fileName.lastIndexOf('.')) + ".out");
		int T = Integer.parseInt(in.readLine());
		for(int i = 1; i <= T; i++) {
			out.print("Case #" + i + ": ");
			String s = in.readLine();
			out.println(recycledNumbers(s));
		}
		out.close();
		in.close();
	}
}