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.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();
	}
}