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.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;


public class RecycledNumbers {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		
		Scanner in;
		/*in = new Scanner(new FileReader("C-small.in"));
		FileWriter output = new FileWriter("C-small.out");*/
		in = new Scanner(new FileReader("C-large.in"));
		FileWriter output = new FileWriter("C-large.out");
		
		int T = in.nextInt();

		for(int i = 1; i <= T; i++) {
			long a = in.nextInt();
			long b = in.nextInt();

			int recycle = 0;
			for(long n = a; n < b; n++) {
				StringBuffer sb = new StringBuffer(Long.toString(n));
				sb.trimToSize();
				long m = -1;
				
				for(int j = 1; j < sb.length(); j++) {
					sb.append(sb.charAt(0));
					sb.deleteCharAt(0);
					sb.trimToSize();

					if ( m != Long.parseLong(sb.toString()) ) {
						long check = m;
						m = Long.parseLong(sb.toString());

						if(m <= b && m>n) {
							//System.out.println(a + " " + n + " " + m + " " + b);
							recycle++;
						} else m = check;
					}
					
				}
			}
			
			output.write("Case #" + i + ": " + recycle + "\n");
			
		}
		
		in.close();
		output.flush();
		output.close();

	}

}
