package qual;

import java.util.Scanner;

public class RecycledNumbers {

	public static void main(String[] args) {
		new RecycledNumbers().run();

	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int result = solve(A, B);
			System.out.printf("Case #%d: %d\n", t + 1, result);
		}
	}

	public int solve(int A, int B) {
		int result = 0;
		for (int i = A; i <= B; i++) {
			int dig = (int) Math.log10(A/*same as B*/) + 1;
			int aa = i;
			for (int d = 0; d < dig - 1; d++) {
				aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
				if (i == aa) {
					break;
				}
				if (i < aa && aa <= B) {
//					System.out.printf("(%d, %d) ", i, aa);
					result++;
				}
			}
		}
		return result;
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

class Input {
	int a;
	int b;
	
	public Input(String line) {
		String [] arr = line.split(" ");
		a = Integer.parseInt(arr[0]);
		b = Integer.parseInt(arr[1]);
	}
	
	public String Rotate(String str) {
		char last = str.charAt(str.length()-1);
		return (last + str.substring(0,str.length()-1));
	}
	
	public int Solve() {
		int count=0;
		int numDigits = Integer.toString(a).length();
		for(int curr=a;curr<=b;curr++) {
			// For each number
			String strCurr = Integer.toString(curr);
			HashMap<String, Integer> checker = new HashMap<String, Integer>();
			
			for(int rot=1;rot<numDigits;rot++) {
				// Rotate it
				strCurr = Rotate(strCurr);
				int newNum = Integer.parseInt(strCurr);
				if(newNum > curr && newNum <= b) {
					String str = curr + "," + newNum;
					if(!checker.containsKey(str)) count++;
					checker.put(str, 0);
				}
			}
		}
		return count;
	}
}

public class Main {
	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		// Setup console
		BufferedReader c = new BufferedReader(new InputStreamReader(System.in));
		
		// Read number of test cases
		int numCases = Integer.parseInt(c.readLine());
		// Input
		Input [] testCases = new Input[numCases];
		for(int i=0;i<numCases;i++) {
			testCases[i] = new Input(c.readLine());
		}
		// Solve
		for(int i=0;i<numCases;i++) {
			int soln = testCases[i].Solve();
			System.out.println("Case #" + (i+1) + ": " + soln);
		}
	}
}

