import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

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