import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		int casos=1, a, b, n, m, cont;
		while(t!=0){
			a=sc.nextInt();
			b=sc.nextInt();
			if(a>b){
				int aux=a;
				a=b;
				b=aux;
			}
			System.out.printf("Case #%d: ",casos++);
			if(a==b){
				System.out.printf("%d\n",0);
			}else{
				cont=0;
				for(n=a;n<b;n++){					
					for(m=n+1;m<=b;m++){					
						if(isRecycled(n,m)) cont++;
					}
				}
				System.out.printf("%d\n",cont);
			}
			t--;
		}		
	}
	public static boolean isRecycled(int n1, int n2){
		String s1, s2, aux;
		s1 =  String.valueOf( n1 );
		s2 =  String.valueOf( n2 );		
		boolean r = false;		
		for(int i=0;i<s1.length();i++){
			aux="";
			aux=s1.substring(i,s1.length())+s1.substring(0,i);
//			System.out.println(aux);
			if(aux.equals(s2)){
				r=true;
				break;
			}
		}		
		return r;
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;


public class C {
	private static final String PROBLEM_NAME = "C-small";

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader r = new BufferedReader(new FileReader(PROBLEM_NAME + ".in"));
		BufferedWriter w = new BufferedWriter(new FileWriter(PROBLEM_NAME + ".out"));
		int testsNumber = Integer.parseInt(r.readLine());
		for (int i = 0; i < testsNumber; ++i) {
			String[] line = r.readLine().split(" ");
			int a = Integer.parseInt(line[0]);
			int b = Integer.parseInt(line[1]);
			long res = 0L;
			
			int len = 0;
			int tmp = a;
			while (tmp != 0) {
				++len;
				tmp /= 10;
			}
			if (a == 0) {
				len = 1;
			}
			
			int m = 1;
			for (int j = 1; j < len; ++j) {
				m *= 10;
			}
			
			while (a < b) {
				Set<Integer> counted = new HashSet<Integer>();
				int t = a;
				boolean sh = false;
				for (int j = 1; j < len; ++j) {
					int x = t % 10;
					if (x == 0) {
						sh = true;
						t = t / 10;
					} else {
						sh = false;
						t = x * m + t / 10;
					}
					if (!sh && t <= b && t > a && !counted.contains(t)) {
						counted.add(t);
						++res;
					}
				}
				++a;
			}
			
			w.write("Case #" + (i + 1) + ": ");
			w.write(res + "");
			w.newLine();
		}
		r.close();
		w.close();
	}
}
