import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class CopyOfCopyOfMain {

	static int ndigits(int n) {
		return (int) (Math.log10(n) + 1);
	}

	static int rot(int n, int dig) {
		return (int) ((n % 10) * Math.pow(10, dig - 1)) + (int) (n / 10);
	}

	public static void main(String[] args) throws FileNotFoundException {
		String file = "C-large";
		Scanner in = new Scanner(new File(file + ".in"));
		PrintWriter out = new PrintWriter(new File(file + ".out"));

		int T = in.nextInt();
		for (int t = 1; t <= T; t++) {
			int A = in.nextInt();
			int B = in.nextInt();

			int c = 0;
			int[] list = new int[ndigits(B)];
			numbers: for (int i = A; i <= B; i++) {
				int digs = ndigits(i);
				int rot = i;
				int pairs = 0;

				Arrays.fill(list, -1);
				list[0] = i;

				digits: for (int j = 1; j <= digs + 1; j++) {

					rot = rot(rot, digs);
					if(rot < i)
						continue;

					if (A <= rot && rot <= B) {
						for (int k = 0; k < j; k++) {
							if (list[k] == rot) {
								continue digits;
							}
						}
						pairs++;
						list[j] = rot;
					}
				}

				//c += pairs * (pairs + 1) / 2;
				c += pairs ;
				// c+=digs;
			}
			out.println("Case #" + t + ": " + c);
		}

		in.close();
		out.close();
	}
}

import java.util.*;


public class RecycledNumbers {

	private static final Scanner sc = new Scanner(System.in);
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		int T = sc.nextInt();
		
		
		for (int i = 0; i < T; i++){
			
			int A = sc.nextInt();
			int B = sc.nextInt();
			
			int m;
			
			HashMap<Integer, Integer> mMap = new HashMap<Integer, Integer>();

			int results = 0;
			
			final int digits = 1 + (int)Math.floor(Math.log10(A));
			
			
			for (int n = A; n < B; n++){
				
				if (digits == 1)
					break;
				
				//System.out.println(n);
					
				m = flipNumber(n, 1);
				mMap.put(m, m);
				
				if (n < m && m <= B)
						results++;
				
				if (digits > 2){
					m = flipNumber(n, 2);
					if (n < m && m <= B && !mMap.containsKey(m)){
						mMap.put(m,	m);
						results++;
					}
				}
				
				
				if (digits > 3){
					m = flipNumber(n, 3);
					if (n < m && m <= B && !mMap.containsKey(m)){
						mMap.put(m,	m);
						results++;
					}
				}
				
				if (digits > 4){
					m = flipNumber(n, 4);
					if (n < m && m <= B && !mMap.containsKey(m)){
						mMap.put(m,	m);
						results++;
					}
				}
				
				if (digits > 5){
					m = flipNumber(n, 5);
					if (n < m && m <= B && !mMap.containsKey(m)){
						mMap.put(m,	m);
						results++;
					}
				}
				
				if (digits > 6){
					m = flipNumber(n, 6);
					if (n < m && m <= B && !mMap.containsKey(m)){
						mMap.put(m,	m);
						results++;
					}
				}
				
				mMap.clear();

				
			}
			System.out.println("Case #" + (i + 1) + ": " + results);

			
		}

	}
	
	private static int flipNumber(int x, int way){
		
		String num = "" + x;
		
		if (way == 1)
			num = num.substring(num.length() - 1) + num.substring(0, num.length() - 1);
		
		else if (way == 2)
			num = num.substring(num.length() - 2) + num.substring(0, num.length() - 2);
		
		else if (way == 3)
			num = num.substring(num.length() - 3) + num.substring(0, num.length() - 3);

		else if (way == 4)
			num = num.substring(num.length() - 4) + num.substring(0, num.length() - 4);

		else if (way == 5)
			num = num.substring(num.length() - 5) + num.substring(0, num.length() - 5);

		else if (way == 6)
			num = num.substring(num.length() - 6) + num.substring(0, num.length() - 6);

		int p = Integer.parseInt(num);
		return p;
		
	}

}
