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.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

class Pair{
	int x;
	int y;
	Pair(int x,int y){
		this.x = x;
		this.y = y;
	}
	public boolean equals(Pair p){
		return this.x == p.x && this.y ==p.y;
	}
}
public class RecycledNumbers {

	static int [] x = new int [300];
	static int count = 0;
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());
		int A,B;
		StringTokenizer st;
		for (int i = 1; i <= T; i++) {
			st = new StringTokenizer(br.readLine());
			A = Integer.parseInt(st.nextToken());
			B = Integer.parseInt(st.nextToken());
			System.out.println("Case #" + i + ": "+get(A,B));
		}
	}

	private static int get(int a, int b) {
		int res = 0;
		for (int i = a; i < b; i++) {
			res += recycled(i,b);
		}
		return res;
	}

	private static int recycled(int a, int lim) {
		HashSet<Integer> set = new HashSet<Integer>();
		int b = a,c;
		String s = a+"";
		int len =s.length()-1;
		for(int i = 0 ; i <= len ; i++ ){
			c = (int) (b/10 + b%10* Math.pow(10, len));
			if(c > a && c <= lim){
				set.add(c);
			}
			b = c;
		}
		return set.size();
	}
}
